Skip to content

Inconsistent bundle behavior of CommonJS between webpack4 and webpack5 #6188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fangbinwei opened this issue Jan 6, 2021 · 0 comments · Fixed by #6218
Closed

Inconsistent bundle behavior of CommonJS between webpack4 and webpack5 #6188

fangbinwei opened this issue Jan 6, 2021 · 0 comments · Fixed by #6218

Comments

@fangbinwei
Copy link
Collaborator

fangbinwei commented Jan 6, 2021

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants