Skip to content

Inconsistent bundle behavior of CommonJS between webpack4 and webpack5  #6188

Closed
@fangbinwei

Description

@fangbinwei

Version

5.0.0-alpha.0

Reproduction link

https://github.com/fangbinwei/vue-cli-issue-webpack5-bundle

Environment info

Environment Info:

  System:
    OS: Windows 10 10.0.17763
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  Binaries:
    Node: 14.15.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - D:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.9 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 87.0.4280.66
    Edge: Spartan (44.17763.831.0)
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1
    @vue/babel-helper-vue-transform-on:  1.0.0
    @vue/babel-plugin-jsx:  1.0.0
    @vue/babel-plugin-transform-vue-jsx:  1.2.1
    @vue/babel-preset-app:  5.0.0-alpha.0
    @vue/babel-preset-jsx:  1.2.4
    @vue/babel-sugar-composition-api-inject-h:  1.2.1
    @vue/babel-sugar-composition-api-render-instance:  1.2.4
    @vue/babel-sugar-functional-vue:  1.2.2
    @vue/babel-sugar-inject-h:  1.2.2
    @vue/babel-sugar-v-model:  1.2.3
    @vue/babel-sugar-v-on:  1.2.3
    @vue/cli-overlay:  5.0.0-alpha.0
    @vue/cli-plugin-babel: ~5.0.0-alpha.0 => 5.0.0-alpha.0
    @vue/cli-plugin-router:  5.0.0-alpha.0
    @vue/cli-plugin-vuex:  5.0.0-alpha.0
    @vue/cli-service: ~5.0.0-alpha.0 => 5.0.0-alpha.0
    @vue/cli-shared-utils:  5.0.0-alpha.0
    @vue/component-compiler-utils:  3.2.0
    @vue/preload-webpack-plugin:  1.1.2
    @vue/web-component-wrapper:  1.2.0
    vue: ^2.6.11 => 2.6.12
    vue-hot-reload-api:  2.3.4
    vue-loader:  16.1.2 (15.9.6)
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.6.11 => 2.6.12
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

build CommonJS lib using --target lib --formats commonjs

npm run build:lib
node test_dist.js

the output of webpack4

module.exports = //...

the output of webpack5

module.exports["my-libname"] = //...

What is expected?

Consistent behavior

What is actually happening?

The behavior of output.library is different from webpack@4 when setting output.libraryTarget: 'commonjs2'

maybe we should omit the output.library when libraryTarget: 'commonjs2' to make the behavior consistent

related issue: webpack/webpack#11800,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions