Skip to content

Commit 3816603

Browse files
committed
Upgrade of webpack configurations for the latest webpack version
1 parent e783b2b commit 3816603

9 files changed

+179
-36
lines changed

config/webpack/app-base.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = function configFactory(ops) {
9696
__dirname: true,
9797
fs: 'empty',
9898
},
99+
mode: o.mode,
99100
output: {
100101
chunkFilename: `[name]-${now.valueOf()}.js`,
101102
filename: `[name]-${now.valueOf()}.js`,
@@ -104,6 +105,7 @@ module.exports = function configFactory(ops) {
104105
},
105106
plugins: [
106107
new ExtractCssChunks({
108+
chunkFilename: `[name]-${now.valueOf()}.js`,
107109
filename: `[name]-${now.valueOf()}.css`,
108110
}),
109111
new webpack.DefinePlugin({
@@ -155,9 +157,8 @@ module.exports = function configFactory(ops) {
155157
}, {
156158
/* Loads SCSS stylesheets. */
157159
test: /\.scss/,
158-
use: ExtractCssChunks.extract({
159-
fallback: 'style-loader',
160-
use: [{
160+
use: [
161+
ExtractCssChunks.loader, {
161162
loader: 'css-loader',
162163
options: {
163164
localIdentName: o.cssLocalIdent,
@@ -173,16 +174,16 @@ module.exports = function configFactory(ops) {
173174
options: {
174175
sourceMap: true,
175176
},
176-
}],
177-
}),
177+
},
178+
],
178179
}, {
179180
/* Loads CSS stylesheets. It is assumed that CSS stylesheets come only
180181
* from dependencies, as we use SCSS inside our own code. */
181182
test: /\.css$/,
182-
use: ExtractCssChunks.extract({
183-
fallback: 'style-loader',
184-
use: ['css-loader'],
185-
}),
183+
use: [
184+
ExtractCssChunks.loader,
185+
'css-loader',
186+
],
186187
}],
187188
},
188189
};

config/webpack/app-development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = function configFactory(ops) {
3232
...ops,
3333
babelEnv: 'development',
3434
cssLocalIdent: '[path][name]___[local]___[hash:base64:6]',
35+
mode: 'development',
3536
}), {
3637
plugins: [
3738
new webpack.DefinePlugin({
@@ -43,7 +44,6 @@ module.exports = function configFactory(ops) {
4344
}),
4445
new webpack.HotModuleReplacementPlugin(),
4546
new webpack.NoEmitOnErrorsPlugin(),
46-
new webpack.NamedModulesPlugin(),
4747
],
4848
});
4949
if (!_.isArray(res.entry.main)) {

config/webpack/app-production.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function configFactory(ops) {
3131
return webpackMerge.smart(baseFactory({
3232
...ops,
3333
babelEnv: 'production',
34+
mode: 'production',
3435
}), {
3536
plugins: [
3637
new webpack.DefinePlugin({
@@ -49,14 +50,6 @@ module.exports = function configFactory(ops) {
4950
zindex: false,
5051
},
5152
}),
52-
53-
/* TODO: It tends to make problems with dynamically loaded chunks,
54-
* I guess it may move some code between modules being in different
55-
* chunks, thus breaking the code when they are loaded in different
56-
* order. Should be further investigated. */
57-
// new webpack.optimize.ModuleConcatenationPlugin(),
58-
59-
new webpack.optimize.UglifyJsPlugin(),
6053
],
6154
});
6255
};

config/webpack/lib-base.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = function configFactory(ops) {
5555
'topcoder-react-utils',
5656
'url-parse',
5757
],
58+
mode: ops.mode,
5859
output: {
5960
filename: 'index.js',
6061
library: ops.library,
@@ -107,9 +108,8 @@ module.exports = function configFactory(ops) {
107108
/* Loads SCSS stylesheets. */
108109
test: /\.scss/,
109110
exclude: /node_modules/,
110-
use: ExtractCssChunks.extract({
111-
fallback: 'style-loader',
112-
use: [{
111+
use: [
112+
ExtractCssChunks.loader, {
113113
loader: 'css-loader',
114114
options: {
115115
importLoaders: 3,
@@ -128,16 +128,16 @@ module.exports = function configFactory(ops) {
128128
options: {
129129
sourceMap: true,
130130
},
131-
}],
132-
}),
131+
},
132+
],
133133
}, {
134134
/* Loads CSS stylesheets. It is assumed that CSS stylesheets come only
135135
* from dependencies, as we use SCSS inside our own code. */
136136
test: /\.css$/,
137-
use: ExtractCssChunks.extract({
138-
fallback: 'style-loader',
139-
use: ['css-loader'],
140-
}),
137+
use: [
138+
ExtractCssChunks.loader,
139+
'css-loader',
140+
],
141141
}],
142142
},
143143
resolve: {

config/webpack/lib-development.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* Development Webpack configuration for ReactJS libraries.
33
*/
44

5-
const webpack = require('webpack');
6-
const webpackMerge = require('webpack-merge');
7-
85
const baseFactory = require('./lib-base');
96

107
/**
@@ -23,14 +20,10 @@ const baseFactory = require('./lib-base');
2320
* @return {Object} Webpack configuration.
2421
*/
2522
module.exports = function configFactory(ops) {
26-
const res = webpackMerge.smart(baseFactory({
23+
return baseFactory({
2724
...ops,
2825
babelEnv: 'development',
2926
cssLocalIdent: '[path][name]___[local]___[hash:base64:6]',
30-
}), {
31-
plugins: [
32-
new webpack.NamedModulesPlugin(),
33-
],
27+
mode: 'development',
3428
});
35-
return res;
3629
};

config/webpack/lib-production.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ module.exports = function configFactory(ops) {
2424
...ops,
2525
babelEnv: 'production',
2626
cssLocalIdent: '[hash:base64:6]',
27+
mode: 'production',
2728
});
2829
};

docs/webpack-config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mutation of the config object.
5656
It allows to re-create the Webpack config during a server launch without
5757
re-generation of the build info file created during a previous build
5858
(and thus bundled into the frontend bundle). Defaults to `false`.
59+
- **`mode`** – *String* – [Webpack mode](https://webpack.js.org/concepts/mode/).
5960
- **`publicPath`** — *String* — Base URL for the output of
6061
the build assets;
6162

@@ -170,6 +171,8 @@ mutation of the config object.
170171
- **`library`** — *String* — Name of the library to be build.
171172
It is important for proper resolution of the library assets.
172173

174+
- **`mode`** – *String* – [Webpack mode](https://webpack.js.org/concepts/mode/).
175+
173176
- The generated config will opt to:
174177
- References to the font assets (EOF, OTF, SVG, TTF, WOFF, WOFF2 files from
175178
the `src/assets/fonts` folder of the library source code) will rewritten

package-lock.json

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"stylelint": "^9.2.1",
8787
"stylelint-config-standard": "^18.2.0",
8888
"webpack": "^4.12.0",
89+
"webpack-cli": "^3.0.3",
8990
"webpack-dev-middleware": "^3.1.3",
9091
"webpack-hot-middleware": "^2.22.2",
9192
"webpack-merge": "^4.1.2"

0 commit comments

Comments
 (0)