Skip to content

Commit c445ac3

Browse files
committed
Optimize Webpack
1 parent aa7c589 commit c445ac3

File tree

4 files changed

+16
-56
lines changed

4 files changed

+16
-56
lines changed

Resources/Build/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
},
3535
"scripts": {
3636
"set-node-version": "n 10",
37-
"webpack:build:dev": "./node_modules/.bin/webpack --config ./webpack.dev.js",
38-
"webpack:build:dev:watch": "./node_modules/.bin/webpack --config ./webpack.dev.js --watch",
39-
"webpack:build:live": "./node_modules/.bin/webpack --config ./webpack.prod.js",
37+
"webpack:build:dev": "./node_modules/.bin/webpack --config ./webpack.dev.js || exit 0",
38+
"webpack:build:dev:watch": "./node_modules/.bin/webpack --config ./webpack.dev.js --watch || exit 0",
39+
"webpack:build:live": "./node_modules/.bin/webpack --config ./webpack.prod.js || exit 0",
4040
"stylelint:fix": "./node_modules/.bin/stylelint --syntax 'scss' ./Assets/Scss/**/*.scss --fix --custom-formatter=./node_modules/stylelint-formatter-pretty || exit 0",
4141
"eslint:fix": "./node_modules/.bin/eslint -c ./.eslintrc.json --fix ./Assets || exit 0"
4242
},

Resources/Build/webpack.common.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const webpack = require('webpack');
33
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
44
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
55
const CleanWebpackPlugin = require('clean-webpack-plugin');
6+
const StyleLintPlugin = require('stylelint-webpack-plugin');
67
const WebpackBar = require('webpackbar');
78
const CopyPlugin = require('copy-webpack-plugin');
89
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
@@ -95,6 +96,7 @@ module.exports = {
9596
{
9697
loader: 'image-webpack-loader',
9798
options: {
99+
cacheFolder: path.resolve('./cache'),
98100
mozjpeg: {
99101
progressive: true,
100102
quality: 65
@@ -128,15 +130,14 @@ module.exports = {
128130
profile: true,
129131
}),
130132
new FriendlyErrorsWebpackPlugin(),
131-
new MiniCssExtractPlugin({
132-
}),
133+
new MiniCssExtractPlugin({}),
133134
new UglifyJsPlugin({
134135
extractComments: true,
135136
sourceMap: true
136137
}),
137138
new CopyPlugin(
138139
[{from: 'Assets/Images/Misc', to: 'Images/Misc'}],
139-
{ copyUnmodified: true }
140+
{copyUnmodified: true}
140141
),
141142
new CopyPlugin([
142143
{from: 'Assets/JavaScripts/static', to: 'JavaScripts'},
@@ -145,6 +146,7 @@ module.exports = {
145146
new ImageminPlugin({
146147
test: /\.(jpe?g|png|gif|svg)$/i,
147148
options: {
149+
cacheFolder: path.resolve('./cache'),
148150
mozjpeg: {
149151
progressive: true,
150152
quality: 65
@@ -165,6 +167,11 @@ module.exports = {
165167
quality: 75
166168
}
167169
}
168-
})
170+
}),
171+
new StyleLintPlugin({
172+
configFile: ".stylelintrc.json",
173+
syntax: 'scss',
174+
files: '**/*.scss',
175+
}),
169176
],
170177
};

Resources/Build/webpack.dev.js

+1-24
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,7 @@ const baseConfig = require('./webpack.common.js');
44

55
const developConfig = {
66
mode: 'development',
7-
devtool: "source-map",
8-
module: {
9-
rules: [
10-
{
11-
enforce: "pre",
12-
test: /\.js$/,
13-
exclude: /node_modules/,
14-
loader: "eslint-loader",
15-
options: {
16-
configFile: '.eslintrc.json'
17-
}
18-
},
19-
]
20-
},
21-
plugins: [
22-
new StyleLintPlugin({
23-
configFile: ".stylelintrc.json",
24-
emitErrors: false,
25-
syntax: 'scss',
26-
files: '**/*.scss',
27-
failOnError: false,
28-
quiet: false,
29-
}),
30-
]
7+
devtool: "source-map"
318
};
329

3310
module.exports = merge.smart(baseConfig, developConfig);

Resources/Build/webpack.prod.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
const merge = require('webpack-merge');
2-
const StyleLintPlugin = require('stylelint-webpack-plugin');
32
const baseConfig = require('./webpack.common.js');
43

54
const productionConfig = {
65
mode: 'production',
7-
performance: {hints: false},
8-
module: {
9-
rules: [
10-
{
11-
enforce: "pre",
12-
test: /\.js$/,
13-
exclude: /node_modules/,
14-
loader: "eslint-loader",
15-
options: {
16-
configFile: '.eslintrc.json'
17-
}
18-
},
19-
]
20-
},
21-
plugins: [
22-
new StyleLintPlugin({
23-
configFile: ".stylelintrc.json",
24-
emitErrors: false,
25-
syntax: 'scss',
26-
files: '**/*.scss',
27-
failOnError: false,
28-
quiet: false,
29-
}),
30-
]
6+
performance: {hints: false}
317
};
328

339
module.exports = merge.smart(baseConfig, productionConfig);

0 commit comments

Comments
 (0)