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

Commit b016aa9

Browse files
committed
[Migration] Webpack 4 - detecting outstanding issues.
Includes a huge amount of additional updates as well.
1 parent 95d80bd commit b016aa9

File tree

8 files changed

+1260
-698
lines changed

8 files changed

+1260
-698
lines changed

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: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
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");
13-
const InlineChunkManifestHtmlWebpackPlugin = require("inline-chunk-manifest-html-webpack-plugin");
149
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
1510
.BundleAnalyzerPlugin;
1611
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
1712
const PurifyCSSPlugin = require("purifycss-webpack");
18-
const WorkboxPlugin = require("workbox-webpack-plugin");
13+
const { InjectManifest } = require("workbox-webpack-plugin");
1914
const glob = require("globby");
2015

2116
const paths = require("../paths");
@@ -28,7 +23,7 @@ if (process.env.NODE_ENV !== "production") {
2823
}
2924

3025
// Note: defined here because it will be used more than once.
31-
const cssFilename = "static/css/[name].[contenthash:8].css";
26+
const cssFilename = "static/css/[name].[chunkhash:8].css"; // TODO: Turn into [contenthash] once available...
3227

3328
// ExtractTextPlugin expects the build output to be flat.
3429
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
@@ -44,43 +39,43 @@ module.exports = function() {
4439
commonConfig(false, extractTextPluginOptions, paths.publicUrl),
4540
{
4641
bail: true,
42+
mode: "production",
4743
entry: paths.appIndex,
4844

4945
// TODO: Handle https://vue-loader.vuejs.org/en/configurations/extract-css.html !
5046

5147
output: {
5248
path: paths.appBuild,
5349
filename: "static/js/[name].[chunkhash:8].js",
54-
chunkFilename: "static/js/[name].[chunkhash:8].chunk.js",
50+
chunkFilename: "static/js/[name].[chunkhash:8].js",
5551
publicPath: paths.publicPath,
5652
devtoolModuleFilenameTemplate: info =>
5753
path.relative(paths.appSrc, info.absoluteResourcePath)
5854
},
5955

56+
optimization: {
57+
splitChunks: {
58+
cacheGroups: {
59+
vendors: {
60+
chunks: "all",
61+
test: /[\\\/]node_modules[\\\/]/,
62+
priority: -10,
63+
name: "vendor"
64+
}
65+
}
66+
},
67+
runtimeChunk: { name: "runtime" }
68+
},
69+
70+
performance: false,
71+
6072
plugins: [
61-
// Plugin to let the whole build fail on any error; i.e. do not tolerate these
62-
new NoEmitOnErrorsPlugin(),
6373
// For more consistent module IDs
6474
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"),
72-
// Generate a manifest file which contains a mapping of all asset filenames
73-
// to their corresponding output file so that tools can pick it up without
74-
// having to parse `index.html`.
75-
// Extracts the chunk manifest and inlines it into the template, while retaining
76-
// the original file.
77-
new InlineChunkManifestHtmlWebpackPlugin({
78-
filename: "asset-manifest.json",
79-
dropAsset: true
80-
}),
8175
// Extract CSS, purify, dedupe and optimize it.
8276
new ExtractTextPlugin({
83-
filename: cssFilename
77+
filename: cssFilename,
78+
allChunks: true
8479
}),
8580
new PurifyCSSPlugin({
8681
paths: glob.sync([
@@ -93,7 +88,8 @@ module.exports = function() {
9388
whitelist: [
9489
"*:not*", // See issue: https://github.com/purifycss/purifycss/issues/161
9590
".notices", // Hierarchy not detected correctly.
96-
".snackbar" // Same
91+
".snackbar", // Same
92+
".carousel-3d-container"
9793
]
9894
}
9995
}),
@@ -118,28 +114,13 @@ module.exports = function() {
118114
logLevel: "silent"
119115
}),
120116

121-
new ModuleConcatenationPlugin(),
122-
123-
new WorkboxPlugin({
117+
new InjectManifest({
118+
importWorkboxFrom: "local", // TODO: See if we can use "local" here, and disable our manual config.
124119
globDirectory: paths.appBuild,
125120
globPatterns: ["**/*.{html,js,css,jpg,eot,svg,woff2,woff,ttf,json}"],
126121
globIgnores: ["**/*.map"],
127-
swDest: path.join(paths.appBuild, "service-worker.js"),
122+
swDest: "service-worker.js",
128123
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
143124
})
144125
]
145126
}

package.json

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,83 +24,82 @@
2424
]
2525
},
2626
"dependencies": {
27-
"av-ts": "^0.9.2",
28-
"lodash-es": "^4.17.5",
27+
"av-ts": "^0.9.3",
28+
"lodash-es": "^4.17.8",
2929
"sanitize.css": "^5.0.0",
3030
"tslib": "^1.9.0",
31-
"vee-validate": "2.0.4",
32-
"vue": "^2.5.13",
31+
"vee-validate": "2.0.6",
32+
"vue": "^2.5.16",
3333
"vue-carousel-3d": "^0.1.20",
34-
"vue-i18n": "^7.4.2",
34+
"vue-i18n": "^7.6.0",
3535
"vue-router": "^3.0.1",
36-
"vuetify": "^1.0.4",
36+
"vuetify": "^1.0.16",
3737
"vuex": "^3.0.1",
3838
"webfontloader": "^1.6.28"
3939
},
4040
"devDependencies": {
41-
"@types/jest": "^22.1.3",
41+
"@types/jest": "^22.2.3",
4242
"@types/lodash-es": "4.17.0",
4343
"@types/webfontloader": "^1.6.29",
44-
"@types/webpack-env": "^1.13.5",
45-
"@vue/test-utils": "^1.0.0-beta.12",
44+
"@types/webpack-env": "^1.13.6",
45+
"@vue/test-utils": "^1.0.0-beta.14",
4646
"autodll-webpack-plugin": "^0.3.9",
47-
"autoprefixer": "^8.0.0",
47+
"autoprefixer": "^8.3.0",
4848
"babel-core": "^6.26.0",
49-
"babel-loader": "^7.1.3",
49+
"babel-loader": "^7.1.4",
5050
"babel-preset-env": "^1.6.1",
51-
"case-sensitive-paths-webpack-plugin": "^2.1.1",
52-
"chalk": "^2.3.1",
51+
"case-sensitive-paths-webpack-plugin": "^2.1.2",
52+
"chalk": "^2.4.0",
5353
"compression": "^1.7.2",
54-
"css-loader": "^0.28.10",
54+
"css-loader": "^0.28.11",
5555
"cssnano": "^3.10.0",
56-
"express": "^4.16.2",
57-
"extract-text-webpack-plugin": "^3.0.2",
58-
"file-loader": "^1.1.10",
59-
"fork-ts-checker-webpack-plugin": "^0.4.0",
56+
"express": "^4.16.3",
57+
"extract-text-webpack-plugin": "^4.0.0-beta.0",
58+
"file-loader": "^1.1.11",
59+
"fork-ts-checker-webpack-plugin": "^0.4.1",
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.4",
63+
"html-webpack-plugin": "^3.2.0",
6464
"http-proxy": "^1.16.2",
6565
"husky": "^0.14.3",
6666
"image-webpack-loader": "^3.4.2",
6767
"imports-loader": "^0.8.0",
68-
"inline-chunk-manifest-html-webpack-plugin": "^2.0.0",
69-
"jest": "^22.4.2",
70-
"lint-staged": "^7.0.0",
68+
"jest": "^22.4.3",
69+
"lint-staged": "^7.0.4",
7170
"lodash": "^4.17.5",
72-
"node-sass": "^4.7.2",
73-
"optimize-css-assets-webpack-plugin": "^3.2.0",
71+
"node-sass": "^4.8.3",
72+
"optimize-css-assets-webpack-plugin": "^4.0.0",
7473
"postcss-flexbugs-fixes": "^3.3.0",
75-
"postcss-loader": "^2.1.1",
76-
"prettier": "^1.11.0",
74+
"postcss-loader": "^2.1.4",
75+
"prettier": "^1.12.1",
7776
"progress-bar-webpack-plugin": "^1.11.0",
7877
"purify-css": "^1.2.5",
7978
"purifycss-webpack": "^0.7.0",
80-
"resolve-url-loader": "^2.2.1",
81-
"sass-loader": "^6.0.6",
79+
"resolve-url-loader": "^2.3.0",
80+
"sass-loader": "^7.0.1",
8281
"shelljs": "^0.8.1",
8382
"strip-ansi": "^4.0.0",
84-
"style-loader": "^0.20.2",
85-
"stylelint": "^9.1.1",
86-
"stylelint-config-standard": "^18.1.0",
83+
"style-loader": "^0.21.0",
84+
"stylelint": "^9.2.0",
85+
"stylelint-config-standard": "^18.2.0",
8786
"stylelint-formatter-pretty": "^1.0.3",
8887
"stylelint-processor-html": "^1.0.0",
89-
"stylelint-scss": "^2.4.0",
90-
"stylelint-webpack-plugin": "^0.10.3",
91-
"ts-jest": "^22.4.0",
92-
"ts-loader": "^3.5.0",
88+
"stylelint-scss": "^3.0.1",
89+
"stylelint-webpack-plugin": "^0.10.4",
90+
"ts-jest": "^22.4.4",
91+
"ts-loader": "^4.2.0",
9392
"tslint": "^5.9.1",
94-
"tslint-config-prettier": "^1.9.0",
95-
"typescript": "2.7.2",
96-
"url-loader": "^0.6.2",
97-
"vue-loader": "^14.1.1",
98-
"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",
93+
"tslint-config-prettier": "^1.10.0",
94+
"typescript": "2.8.1",
95+
"url-loader": "^1.0.1",
96+
"vue-loader": "^14.2.2",
97+
"vue-template-compiler": "^2.5.16",
98+
"vue-template-loader": "^0.4.1",
99+
"webpack": "^4.6.0",
100+
"webpack-bundle-analyzer": "^2.11.1",
101+
"webpack-dev-server": "^3.1.3",
103102
"webpack-merge": "^4.1.2",
104-
"workbox-webpack-plugin": "^2.1.2"
103+
"workbox-webpack-plugin": "^3.1.0"
105104
}
106105
}

scripts/build.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,13 @@ renderLoadingAnimation()
6969
dereference: true,
7070
filter: file => file !== paths.appHtml
7171
});
72-
const pa = require.resolve("workbox-sw"),
73-
swTargetPath = path.join(paths.appBuild, path.basename(pa)),
74-
paMap = pa + ".map",
75-
swMapPath = path.join(paths.appBuild, path.basename(pa) + ".map");
76-
77-
fs.copySync(pa, swTargetPath, {
78-
dereference: true
79-
});
80-
fs.copySync(paMap, swMapPath, {
81-
dereference: true
82-
});
83-
84-
// Update service-worker script to properly update its referenced Workbox.js version.
85-
shelljs.sed(
86-
"-i",
87-
/workbox-sw\.prod\.v\d.\d.\d\.js/i,
88-
path.basename(pa),
89-
path.resolve(paths.appSrc, "service-worker.js")
90-
);
9172

9273
// Determine copied paths, and add the generated service worker stuff as well
9374
// used for properly generating an output.
9475
const staticAssets = glob
9576
.sync([paths.appPublic + "/**/*", `!${paths.appPublic}/index.html`])
9677
.map(p => path.relative(paths.appPublic, p));
9778

98-
staticAssets.push(
99-
path.relative(paths.appBuild, swTargetPath),
100-
path.relative(paths.appBuild, swMapPath),
101-
"service-worker.js"
102-
);
103-
10479
out.info("Processing build...").endl();
10580

10681
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)