webpacker 6.0.0.pre.2 → 6.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +5 -2
- data/.github/workflows/js-lint.yml +5 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +17 -14
- data/.node-version +1 -1
- data/.rubocop.yml +106 -0
- data/CHANGELOG.md +36 -9
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +93 -90
- data/README.md +363 -107
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -29
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +57 -25
- data/docs/v6_upgrade.md +75 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/config/webpacker.yml +5 -7
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +4 -3
- data/lib/install/template.rb +17 -10
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/webpacker.rb +1 -1
- data/lib/webpacker/commands.rb +2 -1
- data/lib/webpacker/compiler.rb +9 -3
- data/lib/webpacker/configuration.rb +19 -8
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +7 -2
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +26 -50
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- data/lib/webpacker/railtie.rb +1 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +1 -0
- data/package.json +25 -29
- data/package/__tests__/development.js +3 -2
- data/package/__tests__/env.js +8 -4
- data/package/__tests__/index.js +9 -0
- data/package/babel/preset.js +24 -14
- data/package/env.js +7 -1
- data/package/environments/__tests__/base.js +7 -7
- data/package/environments/base.js +25 -25
- data/package/environments/development.js +7 -8
- data/package/environments/production.js +28 -30
- data/package/index.js +9 -2
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +5 -3
- data/package/rules/file.js +5 -3
- data/package/rules/index.js +9 -17
- data/package/rules/less.js +14 -10
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +12 -9
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -30
- data/package/utils/helpers.js +25 -0
- data/test/configuration_test.rb +3 -3
- data/test/dev_server_runner_test.rb +13 -2
- data/test/helper_test.rb +59 -60
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +4 -4
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
- data/test/test_app/config/webpacker.yml +4 -6
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +19 -5
- data/test/webpacker_test.rb +17 -0
- data/yarn.lock +1567 -1039
- metadata +24 -36
- data/docs/assets.md +0 -135
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -303
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -68
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -187
- data/docs/react.md +0 -183
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -147
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -94
- data/docs/webpack.md +0 -315
- data/docs/yarn.md +0 -23
- data/lib/install/examples/vue3/app.vue +0 -27
- data/lib/install/examples/vue3/hello_vue.js +0 -15
- data/lib/install/javascript/packs/application.css +0 -9
- data/package/babel/preset-react.js +0 -62
- data/package/rules/svg.js +0 -23
data/lib/webpacker/version.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "6.0.0-
|
3
|
+
"version": "6.0.0-rc.1",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -8,40 +8,36 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": "
|
12
|
-
"yarn": ">=1 <
|
11
|
+
"node": "^12 || >=14",
|
12
|
+
"yarn": ">=1 <4"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
15
|
-
"@babel/core": "^7.
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
17
|
-
"@babel/plugin-transform-runtime": "^7.
|
18
|
-
"@babel/preset-env": "^7.
|
19
|
-
"@babel/runtime": "^7.
|
15
|
+
"@babel/core": "^7.15.0",
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
17
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
18
|
+
"@babel/preset-env": "^7.15.0",
|
19
|
+
"@babel/runtime": "^7.15.3",
|
20
20
|
"babel-loader": "^8.2.2",
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"core-js": "^3.8.0",
|
25
|
-
"glob": "^7.1.6",
|
26
|
-
"js-yaml": "^3.14.0",
|
21
|
+
"compression-webpack-plugin": "^7.1.2",
|
22
|
+
"glob": "^7.1.7",
|
23
|
+
"js-yaml": "^3.14.1",
|
27
24
|
"path-complete-extname": "^1.0.0",
|
28
|
-
"pnp-webpack-plugin": "^1.
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"webpack": "^5.
|
32
|
-
"webpack-
|
33
|
-
"webpack-
|
34
|
-
"webpack-
|
35
|
-
"webpack-sources": "^2.2.0"
|
25
|
+
"pnp-webpack-plugin": "^1.7.0",
|
26
|
+
"terser-webpack-plugin": "^5.1.4",
|
27
|
+
"webpack": "^5.50.0",
|
28
|
+
"webpack-assets-manifest": "^5.0.6",
|
29
|
+
"webpack-cli": "^4.8.0",
|
30
|
+
"webpack-merge": "^5.8.0",
|
31
|
+
"webpack-sources": "^3.2.0"
|
36
32
|
},
|
37
33
|
"devDependencies": {
|
38
|
-
"eslint": "^7.
|
39
|
-
"eslint-config-airbnb": "^18.2.
|
40
|
-
"eslint-config-prettier": "^7.
|
41
|
-
"eslint-plugin-import": "^2.
|
42
|
-
"eslint-plugin-jsx-a11y": "^6.
|
43
|
-
"eslint-plugin-react": "^7.
|
44
|
-
"jest": "^26.
|
34
|
+
"eslint": "^7.32.0",
|
35
|
+
"eslint-config-airbnb": "^18.2.1",
|
36
|
+
"eslint-config-prettier": "^7.2.0",
|
37
|
+
"eslint-plugin-import": "^2.24.0",
|
38
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
39
|
+
"eslint-plugin-react": "^7.24.0",
|
40
|
+
"jest": "^26.6.3"
|
45
41
|
},
|
46
42
|
"jest": {
|
47
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
@@ -14,7 +14,7 @@ describe('Development environment', () => {
|
|
14
14
|
test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
|
15
15
|
process.env.RAILS_ENV = 'development'
|
16
16
|
process.env.NODE_ENV = 'development'
|
17
|
-
process.env.WEBPACK_DEV_SERVER = '
|
17
|
+
process.env.WEBPACK_DEV_SERVER = 'true'
|
18
18
|
const { webpackConfig } = require('../index')
|
19
19
|
|
20
20
|
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
@@ -22,7 +22,8 @@ describe('Development environment', () => {
|
|
22
22
|
expect(webpackConfig).toMatchObject({
|
23
23
|
devServer: {
|
24
24
|
host: 'localhost',
|
25
|
-
port: 3035
|
25
|
+
port: 3035,
|
26
|
+
injectClient: false
|
26
27
|
}
|
27
28
|
})
|
28
29
|
})
|
data/package/__tests__/env.js
CHANGED
@@ -15,7 +15,8 @@ describe('Env', () => {
|
|
15
15
|
railsEnv: 'development',
|
16
16
|
nodeEnv: 'development',
|
17
17
|
isProduction: false,
|
18
|
-
isDevelopment: true
|
18
|
+
isDevelopment: true,
|
19
|
+
runningWebpackDevServer: false
|
19
20
|
})
|
20
21
|
})
|
21
22
|
|
@@ -26,7 +27,8 @@ describe('Env', () => {
|
|
26
27
|
railsEnv: 'development',
|
27
28
|
nodeEnv: 'production',
|
28
29
|
isProduction: true,
|
29
|
-
isDevelopment: false
|
30
|
+
isDevelopment: false,
|
31
|
+
runningWebpackDevServer: false
|
30
32
|
})
|
31
33
|
})
|
32
34
|
|
@@ -37,7 +39,8 @@ describe('Env', () => {
|
|
37
39
|
railsEnv: 'production',
|
38
40
|
nodeEnv: 'production',
|
39
41
|
isProduction: true,
|
40
|
-
isDevelopment: false
|
42
|
+
isDevelopment: false,
|
43
|
+
runningWebpackDevServer: false
|
41
44
|
})
|
42
45
|
})
|
43
46
|
|
@@ -48,7 +51,8 @@ describe('Env', () => {
|
|
48
51
|
railsEnv: 'staging',
|
49
52
|
nodeEnv: 'production',
|
50
53
|
isProduction: true,
|
51
|
-
isDevelopment: false
|
54
|
+
isDevelopment: false,
|
55
|
+
runningWebpackDevServer: false
|
52
56
|
})
|
53
57
|
})
|
54
58
|
})
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const index = require('../index')
|
2
|
+
|
3
|
+
describe('index', () => {
|
4
|
+
test('exports webpack-merge v5 functions', () => {
|
5
|
+
expect(index.merge).toBeInstanceOf(Function)
|
6
|
+
expect(index.mergeWithRules).toBeInstanceOf(Function)
|
7
|
+
expect(index.mergeWithCustomize).toBeInstanceOf(Function)
|
8
|
+
})
|
9
|
+
})
|
data/package/babel/preset.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
const { moduleExists } = require('@rails/webpacker')
|
2
|
+
|
1
3
|
module.exports = function config(api) {
|
2
4
|
const validEnv = ['development', 'test', 'production']
|
3
5
|
const currentEnv = api.env()
|
@@ -7,16 +9,15 @@ module.exports = function config(api) {
|
|
7
9
|
|
8
10
|
if (!validEnv.includes(currentEnv)) {
|
9
11
|
throw new Error(
|
10
|
-
`Please specify a valid NODE_ENV or BABEL_ENV environment variable. Valid values are "development", "test", and "production". Instead, received: "${JSON.stringify(
|
12
|
+
`Please specify a valid NODE_ENV or BABEL_ENV environment variable. Valid values are "development", "test", and "production". Instead, received: "${JSON.stringify(
|
13
|
+
currentEnv
|
14
|
+
)}".`
|
11
15
|
)
|
12
16
|
}
|
13
17
|
|
14
18
|
return {
|
15
19
|
presets: [
|
16
|
-
isTestEnv && [
|
17
|
-
'@babel/preset-env',
|
18
|
-
{ targets: { node: 'current' } }
|
19
|
-
],
|
20
|
+
isTestEnv && ['@babel/preset-env', { targets: { node: 'current' } }],
|
20
21
|
(isProductionEnv || isDevelopmentEnv) && [
|
21
22
|
'@babel/preset-env',
|
22
23
|
{
|
@@ -27,18 +28,27 @@ module.exports = function config(api) {
|
|
27
28
|
loose: true,
|
28
29
|
exclude: ['transform-typeof-symbol']
|
29
30
|
}
|
31
|
+
],
|
32
|
+
moduleExists('@babel/preset-typescript') && [
|
33
|
+
'@babel/preset-typescript',
|
34
|
+
{ allExtensions: true, isTSX: true }
|
35
|
+
],
|
36
|
+
moduleExists('@babel/preset-react') && [
|
37
|
+
'@babel/preset-react',
|
38
|
+
{
|
39
|
+
development: isDevelopmentEnv || isTestEnv,
|
40
|
+
useBuiltIns: true
|
41
|
+
}
|
30
42
|
]
|
31
43
|
].filter(Boolean),
|
32
44
|
plugins: [
|
33
|
-
'babel
|
34
|
-
[
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
{ helpers: false }
|
41
|
-
]
|
45
|
+
['@babel/plugin-proposal-class-properties', { loose: true }],
|
46
|
+
['@babel/plugin-transform-runtime', { helpers: false }],
|
47
|
+
isProductionEnv &&
|
48
|
+
moduleExists('babel-plugin-transform-react-remove-prop-types') && [
|
49
|
+
'babel-plugin-transform-react-remove-prop-types',
|
50
|
+
{ removeImport: true }
|
51
|
+
]
|
42
52
|
].filter(Boolean)
|
43
53
|
}
|
44
54
|
}
|
data/package/env.js
CHANGED
@@ -16,9 +16,15 @@ const config = safeLoad(readFileSync(configPath), 'utf8')
|
|
16
16
|
const availableEnvironments = Object.keys(config).join('|')
|
17
17
|
const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
|
18
18
|
|
19
|
+
// v4 of webpack-dev-server will switch to WEBPACK_DEV_SERVE
|
20
|
+
// https://github.com/rails/webpacker/issues/3057
|
21
|
+
const runningWebpackDevServer = process.env.WEBPACK_DEV_SERVER === 'true' ||
|
22
|
+
process.env.WEBPACK_DEV_SERVE === 'true'
|
23
|
+
|
19
24
|
module.exports = {
|
20
25
|
railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
|
21
26
|
nodeEnv,
|
22
27
|
isProduction,
|
23
|
-
isDevelopment
|
28
|
+
isDevelopment,
|
29
|
+
runningWebpackDevServer
|
24
30
|
}
|
@@ -17,21 +17,21 @@ describe('Base config', () => {
|
|
17
17
|
describe('config', () => {
|
18
18
|
test('should return entry', () => {
|
19
19
|
expect(baseConfig.entry.application).toEqual(
|
20
|
-
resolve('app', '
|
20
|
+
resolve('app', 'packs', 'entrypoints', 'application.js')
|
21
21
|
)
|
22
22
|
})
|
23
23
|
|
24
24
|
test('should return multi file entry points', () => {
|
25
25
|
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
26
|
-
resolve('app', '
|
27
|
-
resolve('app', '
|
26
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
|
27
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
|
28
28
|
])
|
29
29
|
})
|
30
30
|
|
31
31
|
test('should return output', () => {
|
32
|
-
expect(baseConfig.output.filename).toEqual('js/[name]
|
32
|
+
expect(baseConfig.output.filename).toEqual('js/[name].js')
|
33
33
|
expect(baseConfig.output.chunkFilename).toEqual(
|
34
|
-
'js/[name]
|
34
|
+
'js/[name].chunk.js'
|
35
35
|
)
|
36
36
|
})
|
37
37
|
|
@@ -44,7 +44,7 @@ describe('Base config', () => {
|
|
44
44
|
})
|
45
45
|
|
46
46
|
test('should return default plugins', () => {
|
47
|
-
expect(baseConfig.plugins.length).toEqual(
|
47
|
+
expect(baseConfig.plugins.length).toEqual(2)
|
48
48
|
})
|
49
49
|
|
50
50
|
test('should return default resolveLoader', () => {
|
@@ -53,7 +53,7 @@ describe('Base config', () => {
|
|
53
53
|
|
54
54
|
test('should return default resolve.modules with additions', () => {
|
55
55
|
expect(baseConfig.resolve.modules).toEqual([
|
56
|
-
resolve('app', '
|
56
|
+
resolve('app', 'packs'),
|
57
57
|
resolve('app/assets'),
|
58
58
|
resolve('/etc/yarn'),
|
59
59
|
resolve('some.config.js'),
|
@@ -4,19 +4,19 @@
|
|
4
4
|
const { basename, dirname, join, relative, resolve } = require('path')
|
5
5
|
const extname = require('path-complete-extname')
|
6
6
|
const PnpWebpackPlugin = require('pnp-webpack-plugin')
|
7
|
-
const { sync } = require('glob')
|
8
|
-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
7
|
+
const { sync: globSync } = require('glob')
|
9
8
|
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
10
9
|
const webpack = require('webpack')
|
11
10
|
const rules = require('../rules')
|
11
|
+
const { isProduction } = require('../env')
|
12
12
|
const config = require('../config')
|
13
|
-
const {
|
13
|
+
const { moduleExists } = require('../utils/helpers')
|
14
14
|
|
15
15
|
const getEntryObject = () => {
|
16
16
|
const entries = {}
|
17
17
|
const rootPath = join(config.source_path, config.source_entry_path)
|
18
18
|
|
19
|
-
|
19
|
+
globSync(`${rootPath}/**/*.*`).forEach((path) => {
|
20
20
|
const namespace = relative(join(rootPath), dirname(path))
|
21
21
|
const name = join(namespace, basename(path, extname(path)))
|
22
22
|
let assetPaths = resolve(path)
|
@@ -52,8 +52,6 @@ const getModulePaths = () => {
|
|
52
52
|
const getPlugins = () => {
|
53
53
|
const plugins = [
|
54
54
|
new webpack.EnvironmentPlugin(process.env),
|
55
|
-
PnpWebpackPlugin,
|
56
|
-
new CaseSensitivePathsPlugin(),
|
57
55
|
new WebpackAssetsManifest({
|
58
56
|
entrypoints: true,
|
59
57
|
writeToDisk: true,
|
@@ -63,37 +61,39 @@ const getPlugins = () => {
|
|
63
61
|
})
|
64
62
|
]
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
} catch (e) {
|
77
|
-
/* Work out what to print here */
|
64
|
+
if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
|
65
|
+
const hash = isProduction ? '-[contenthash:8]' : ''
|
66
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
67
|
+
plugins.push(
|
68
|
+
new MiniCssExtractPlugin({
|
69
|
+
filename: `css/[name]${hash}.css`,
|
70
|
+
chunkFilename: `css/[id]${hash}.css`
|
71
|
+
})
|
72
|
+
)
|
78
73
|
}
|
79
74
|
|
80
75
|
return plugins
|
81
76
|
}
|
82
77
|
|
78
|
+
// Don't use contentHash except for production for performance
|
79
|
+
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
80
|
+
const hash = isProduction ? '-[contenthash]' : ''
|
83
81
|
module.exports = {
|
84
82
|
mode: 'production',
|
85
83
|
output: {
|
86
|
-
filename:
|
87
|
-
chunkFilename:
|
88
|
-
|
89
|
-
|
84
|
+
filename: `js/[name]${hash}.js`,
|
85
|
+
chunkFilename: `js/[name]${hash}.chunk.js`,
|
86
|
+
|
87
|
+
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
88
|
+
hotUpdateChunkFilename: 'js/[id].[fullhash].hot-update.js',
|
90
89
|
path: config.outputPath,
|
91
90
|
publicPath: config.publicPath
|
92
91
|
},
|
93
92
|
entry: getEntryObject(),
|
94
93
|
resolve: {
|
95
|
-
extensions: ['.js', '.mjs', '.ts'],
|
96
|
-
modules: getModulePaths()
|
94
|
+
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.coffee'],
|
95
|
+
modules: getModulePaths(),
|
96
|
+
plugins: [PnpWebpackPlugin]
|
97
97
|
},
|
98
98
|
|
99
99
|
plugins: getPlugins(),
|
@@ -106,7 +106,7 @@ module.exports = {
|
|
106
106
|
optimization: {
|
107
107
|
splitChunks: { chunks: 'all' },
|
108
108
|
|
109
|
-
runtimeChunk:
|
109
|
+
runtimeChunk: 'single'
|
110
110
|
},
|
111
111
|
|
112
112
|
module: {
|
@@ -1,8 +1,8 @@
|
|
1
1
|
const { merge } = require('webpack-merge')
|
2
|
-
const webpack = require('webpack')
|
3
2
|
|
4
3
|
const baseConfig = require('./base')
|
5
4
|
const devServer = require('../dev_server')
|
5
|
+
const { runningWebpackDevServer } = require('../env')
|
6
6
|
|
7
7
|
const { outputPath: contentBase, publicPath } = require('../config')
|
8
8
|
|
@@ -11,14 +11,10 @@ let devConfig = {
|
|
11
11
|
devtool: 'cheap-module-source-map'
|
12
12
|
}
|
13
13
|
|
14
|
-
if (
|
15
|
-
process.env.WEBPACK_DEV_SERVER &&
|
16
|
-
process.env.WEBPACK_DEV_SERVER !== 'undefined'
|
17
|
-
) {
|
14
|
+
if (runningWebpackDevServer) {
|
18
15
|
if (devServer.hmr) {
|
19
16
|
devConfig = merge(devConfig, {
|
20
|
-
output: { filename: '[name]-[hash].js' }
|
21
|
-
plugins: [new webpack.HotModuleReplacementPlugin()]
|
17
|
+
output: { filename: '[name]-[hash].js' }
|
22
18
|
})
|
23
19
|
}
|
24
20
|
|
@@ -33,7 +29,9 @@ if (
|
|
33
29
|
https: devServer.https,
|
34
30
|
hot: devServer.hmr,
|
35
31
|
contentBase,
|
36
|
-
inline: devServer.inline,
|
32
|
+
inline: devServer.inline || devServer.hmr,
|
33
|
+
injectClient: devServer.hmr,
|
34
|
+
injectHot: devServer.hmr,
|
37
35
|
useLocalIp: devServer.use_local_ip,
|
38
36
|
public: devServer.public,
|
39
37
|
publicPath,
|
@@ -41,6 +39,7 @@ if (
|
|
41
39
|
headers: devServer.headers,
|
42
40
|
overlay: devServer.overlay,
|
43
41
|
stats: {
|
42
|
+
colors: true,
|
44
43
|
entrypoints: false,
|
45
44
|
errorDetails: true,
|
46
45
|
modules: false,
|
@@ -5,45 +5,42 @@ const { merge } = require('webpack-merge')
|
|
5
5
|
const CompressionPlugin = require('compression-webpack-plugin')
|
6
6
|
const TerserPlugin = require('terser-webpack-plugin')
|
7
7
|
const baseConfig = require('./base')
|
8
|
+
const { moduleExists } = require('../utils/helpers')
|
8
9
|
|
9
10
|
const getPlugins = () => {
|
10
|
-
|
11
|
-
filename: '[path].gz[query]',
|
12
|
-
algorithm: 'gzip',
|
13
|
-
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
14
|
-
})
|
11
|
+
const plugins = []
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
filename: '[path].
|
19
|
-
algorithm: '
|
13
|
+
plugins.push(
|
14
|
+
new CompressionPlugin({
|
15
|
+
filename: '[path][base].gz[query]',
|
16
|
+
algorithm: 'gzip',
|
20
17
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
21
18
|
})
|
19
|
+
)
|
20
|
+
|
21
|
+
if ('brotli' in process.versions) {
|
22
|
+
plugins.push(
|
23
|
+
new CompressionPlugin({
|
24
|
+
filename: '[path][base].br[query]',
|
25
|
+
algorithm: 'brotliCompress',
|
26
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
27
|
+
})
|
28
|
+
)
|
22
29
|
}
|
23
30
|
|
24
|
-
|
31
|
+
return plugins
|
32
|
+
}
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
new OptimizeCSSAssetsPlugin({
|
34
|
-
parser: safePostCssParser,
|
35
|
-
map: {
|
36
|
-
inline: false,
|
37
|
-
annotation: true
|
38
|
-
}
|
39
|
-
})
|
40
|
-
)
|
41
|
-
}
|
42
|
-
} catch (e) {
|
43
|
-
/* Work out what to output without clutter */
|
34
|
+
const tryCssMinimizer = () => {
|
35
|
+
if (
|
36
|
+
moduleExists('css-loader') &&
|
37
|
+
moduleExists('css-minimizer-webpack-plugin')
|
38
|
+
) {
|
39
|
+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
40
|
+
return new CssMinimizerPlugin()
|
44
41
|
}
|
45
42
|
|
46
|
-
return
|
43
|
+
return null
|
47
44
|
}
|
48
45
|
|
49
46
|
const productionConfig = {
|
@@ -53,6 +50,7 @@ const productionConfig = {
|
|
53
50
|
plugins: getPlugins(),
|
54
51
|
optimization: {
|
55
52
|
minimizer: [
|
53
|
+
tryCssMinimizer(),
|
56
54
|
new TerserPlugin({
|
57
55
|
parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
|
58
56
|
terserOptions: {
|
@@ -74,7 +72,7 @@ const productionConfig = {
|
|
74
72
|
}
|
75
73
|
}
|
76
74
|
})
|
77
|
-
]
|
75
|
+
].filter(Boolean)
|
78
76
|
}
|
79
77
|
}
|
80
78
|
|