Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.

Commit bc04fcf

Browse files
committed
[Migration] Webpack 4 - detecting outstanding issues.
1 parent 95d80bd commit bc04fcf

File tree

7 files changed

+483
-359
lines changed

7 files changed

+483
-359
lines changed

config/webpack/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ module.exports = function(isDev, extractTextPluginOptions, publicUrl) {
276276
formatter: "codeframe"
277277
}),
278278

279-
new StyleLintPlugin(styleLintConfig),
279+
// new StyleLintPlugin(styleLintConfig), // TODO: Need to re-enable this for webpack 4.
280280

281281
new ProgressBarPlugin({
282282
clear: true,

config/webpack/dev.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const path = require("path");
44
const chalk = require("chalk");
55
const { NoEmitOnErrorsPlugin } = require("webpack");
66
const HotModuleReplacementPlugin = require("webpack/lib/HotModuleReplacementPlugin");
7-
const NamedModulesPlugin = require("webpack/lib/NamedModulesPlugin");
87
const merge = require("webpack-merge");
98
const AutoDllPlugin = require("autodll-webpack-plugin");
109
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
@@ -25,6 +24,7 @@ module.exports = function() {
2524
return merge.smartStrategy({ plugins: "prepend" })(
2625
commonConfig(true, {}, publicUrl),
2726
{
27+
mode: "development",
2828
entry: [
2929
require.resolve("webpack-dev-server/client") + "?/",
3030
require.resolve("webpack/hot/dev-server"),
@@ -41,8 +41,11 @@ module.exports = function() {
4141
path.resolve(info.absoluteResourcePath)
4242
},
4343

44+
optimization: {
45+
noEmitOnErrors: true
46+
},
47+
4448
plugins: [
45-
new NamedModulesPlugin(),
4649
new HotModuleReplacementPlugin(),
4750
new NoEmitOnErrorsPlugin(),
4851
new ErrorFormatterPlugin({
@@ -54,7 +57,7 @@ module.exports = function() {
5457
`
5558
]
5659
}),
57-
new AutoDllPlugin(dllConfig),
60+
// new AutoDllPlugin(dllConfig), // TODO: Need to re-enable this for webpack 4.
5861
// See https://github.com/mzgoddard/hard-source-webpack-plugin
5962
new HardSourceWebpackPlugin()
6063
]

config/webpack/plugins/ErrorFormatterPlugin.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ function msToPeriod(ms) {
4040
return result.join(" ");
4141
}
4242

43+
function hookToCompiler(compiler, event, callback) {
44+
if (compiler.hooks[event]) {
45+
compiler.hooks[event].tap("ErrorFormatterPlugin", callback);
46+
} else {
47+
compiler.on(event, callback);
48+
}
49+
}
50+
4351
class ErrorFormatterPlugin {
4452
constructor(options) {
4553
this.options = options || {};
@@ -64,7 +72,7 @@ class ErrorFormatterPlugin {
6472
}
6573

6674
apply(compiler) {
67-
compiler.plugin("done", stats => {
75+
const onDone = stats => {
6876
this.options.clear.onDone && this.cls();
6977
const hasErrors = stats.hasErrors();
7078
const hasWarnings = stats.hasWarnings();
@@ -88,12 +96,15 @@ class ErrorFormatterPlugin {
8896
this.out.errorLabel(`Compilation failed after ${time}. `).endl();
8997
this.displayMalfunctions(hasErrors, hasWarnings, stats);
9098
}
91-
});
99+
};
92100

93-
compiler.plugin("invalid", () => {
101+
const onInvalid = () => {
94102
this.options.clear.onInvalid && this.cls();
95103
this.out.info("Compiling...").endl();
96-
});
104+
};
105+
106+
hookToCompiler(compiler, "done", onDone);
107+
hookToCompiler(compiler, "invalid", onInvalid);
97108
}
98109

99110
displayMalfunctions(hasErrors, hasWarnings, stats) {

config/webpack/prod.js

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
const path = require("path");
44
const merge = require("webpack-merge");
5-
const { NoEmitOnErrorsPlugin } = require("webpack");
65

7-
const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
86
const HashedModuleIdsPlugin = require("webpack/lib/HashedModuleIdsPlugin");
9-
const UglifyJsPlugin = require("webpack/lib/optimize/UglifyJsPlugin");
10-
const ModuleConcatenationPlugin = require("webpack/lib/optimize/ModuleConcatenationPlugin");
117

128
const ExtractTextPlugin = require("extract-text-webpack-plugin");
139
const InlineChunkManifestHtmlWebpackPlugin = require("inline-chunk-manifest-html-webpack-plugin");
@@ -44,6 +40,7 @@ module.exports = function() {
4440
commonConfig(false, extractTextPluginOptions, paths.publicUrl),
4541
{
4642
bail: true,
43+
mode: "production",
4744
entry: paths.appIndex,
4845

4946
// TODO: Handle https://vue-loader.vuejs.org/en/configurations/extract-css.html !
@@ -57,18 +54,23 @@ module.exports = function() {
5754
path.relative(paths.appSrc, info.absoluteResourcePath)
5855
},
5956

57+
optimization: {
58+
splitChunks: {
59+
cacheGroups: {
60+
vendors: {
61+
chunks: "all",
62+
test: /[\\\/]node_modules[\\\/]/,
63+
priority: -10,
64+
name: "vendor"
65+
}
66+
}
67+
},
68+
runtimeChunk: { name: "runtime" }
69+
},
70+
6071
plugins: [
61-
// Plugin to let the whole build fail on any error; i.e. do not tolerate these
62-
new NoEmitOnErrorsPlugin(),
6372
// For more consistent module IDs
6473
new HashedModuleIdsPlugin(),
65-
// Creates a dynamic vendor chunk by including all entries from the `node_modules` directory.
66-
new CommonsChunkPlugin({
67-
name: "vendor",
68-
minChunks: ({ resource }) => /node_modules/.test(resource)
69-
}),
70-
// Externalizes the application manifest.
71-
new CommonsChunkPlugin("manifest"),
7274
// Generate a manifest file which contains a mapping of all asset filenames
7375
// to their corresponding output file so that tools can pick it up without
7476
// having to parse `index.html`.
@@ -118,28 +120,12 @@ module.exports = function() {
118120
logLevel: "silent"
119121
}),
120122

121-
new ModuleConcatenationPlugin(),
122-
123123
new WorkboxPlugin({
124124
globDirectory: paths.appBuild,
125125
globPatterns: ["**/*.{html,js,css,jpg,eot,svg,woff2,woff,ttf,json}"],
126126
globIgnores: ["**/*.map"],
127127
swDest: path.join(paths.appBuild, "service-worker.js"),
128128
swSrc: path.join(paths.appSrc, "service-worker.js")
129-
}),
130-
131-
new UglifyJsPlugin({
132-
compress: {
133-
warnings: false,
134-
// This feature has been reported as buggy a few times, such as:
135-
// https://github.com/mishoo/UglifyJS2/issues/1964
136-
// We'll wait with enabling it by default until it is more solid.
137-
reduce_vars: false
138-
},
139-
output: {
140-
comments: false
141-
},
142-
sourceMap: true
143129
})
144130
]
145131
}

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"lodash-es": "^4.17.5",
2929
"sanitize.css": "^5.0.0",
3030
"tslib": "^1.9.0",
31-
"vee-validate": "2.0.4",
31+
"vee-validate": "2.0.5",
3232
"vue": "^2.5.13",
3333
"vue-carousel-3d": "^0.1.20",
3434
"vue-i18n": "^7.4.2",
@@ -38,29 +38,29 @@
3838
"webfontloader": "^1.6.28"
3939
},
4040
"devDependencies": {
41-
"@types/jest": "^22.1.3",
41+
"@types/jest": "^22.1.4",
4242
"@types/lodash-es": "4.17.0",
4343
"@types/webfontloader": "^1.6.29",
4444
"@types/webpack-env": "^1.13.5",
4545
"@vue/test-utils": "^1.0.0-beta.12",
4646
"autodll-webpack-plugin": "^0.3.9",
47-
"autoprefixer": "^8.0.0",
47+
"autoprefixer": "^8.1.0",
4848
"babel-core": "^6.26.0",
4949
"babel-loader": "^7.1.3",
5050
"babel-preset-env": "^1.6.1",
5151
"case-sensitive-paths-webpack-plugin": "^2.1.1",
52-
"chalk": "^2.3.1",
52+
"chalk": "^2.3.2",
5353
"compression": "^1.7.2",
5454
"css-loader": "^0.28.10",
5555
"cssnano": "^3.10.0",
5656
"express": "^4.16.2",
57-
"extract-text-webpack-plugin": "^3.0.2",
58-
"file-loader": "^1.1.10",
57+
"extract-text-webpack-plugin": "^4.0.0-beta.0",
58+
"file-loader": "^1.1.11",
5959
"fork-ts-checker-webpack-plugin": "^0.4.0",
6060
"fs-extra": "^5.0.0",
6161
"globby": "^8.0.1",
62-
"hard-source-webpack-plugin": "^0.6.0",
63-
"html-webpack-plugin": "^2.30.1",
62+
"hard-source-webpack-plugin": "^0.6.1",
63+
"html-webpack-plugin": "^3.0.4",
6464
"http-proxy": "^1.16.2",
6565
"husky": "^0.14.3",
6666
"image-webpack-loader": "^3.4.2",
@@ -70,37 +70,37 @@
7070
"lint-staged": "^7.0.0",
7171
"lodash": "^4.17.5",
7272
"node-sass": "^4.7.2",
73-
"optimize-css-assets-webpack-plugin": "^3.2.0",
73+
"optimize-css-assets-webpack-plugin": "^4.0.0",
7474
"postcss-flexbugs-fixes": "^3.3.0",
7575
"postcss-loader": "^2.1.1",
76-
"prettier": "^1.11.0",
76+
"prettier": "^1.11.1",
7777
"progress-bar-webpack-plugin": "^1.11.0",
7878
"purify-css": "^1.2.5",
7979
"purifycss-webpack": "^0.7.0",
80-
"resolve-url-loader": "^2.2.1",
81-
"sass-loader": "^6.0.6",
80+
"resolve-url-loader": "^2.3.0",
81+
"sass-loader": "^6.0.7",
8282
"shelljs": "^0.8.1",
8383
"strip-ansi": "^4.0.0",
8484
"style-loader": "^0.20.2",
8585
"stylelint": "^9.1.1",
86-
"stylelint-config-standard": "^18.1.0",
86+
"stylelint-config-standard": "^18.2.0",
8787
"stylelint-formatter-pretty": "^1.0.3",
8888
"stylelint-processor-html": "^1.0.0",
8989
"stylelint-scss": "^2.4.0",
9090
"stylelint-webpack-plugin": "^0.10.3",
91-
"ts-jest": "^22.4.0",
92-
"ts-loader": "^3.5.0",
91+
"ts-jest": "^22.4.1",
92+
"ts-loader": "^4.0.1",
9393
"tslint": "^5.9.1",
9494
"tslint-config-prettier": "^1.9.0",
9595
"typescript": "2.7.2",
96-
"url-loader": "^0.6.2",
96+
"url-loader": "^1.0.1",
9797
"vue-loader": "^14.1.1",
9898
"vue-template-compiler": "^2.5.13",
99-
"vue-template-loader": "^0.4.0",
100-
"webpack": "^3.11.0",
101-
"webpack-bundle-analyzer": "^2.11.0",
102-
"webpack-dev-server": "^2.11.1",
99+
"vue-template-loader": "^0.4.1",
100+
"webpack": "^4.1.0",
101+
"webpack-bundle-analyzer": "^2.11.1",
102+
"webpack-dev-server": "^3.1.0",
103103
"webpack-merge": "^4.1.2",
104-
"workbox-webpack-plugin": "^2.1.2"
104+
"workbox-webpack-plugin": "^2.1.3"
105105
}
106106
}

src/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importScripts("workbox-sw.prod.v2.1.2.js");
1+
importScripts("workbox-sw.prod.v2.1.3.js");
22

33
const workboxSW = new WorkboxSW();
44
workboxSW.precache([]);

0 commit comments

Comments
 (0)