@s-ui/bundler 7.33.0 → 7.36.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sui-bundler-dev.js +13 -8
- package/factories/createCompiler.js +2 -2
- package/factories/createDevServerConfig.js +23 -37
- package/package.json +17 -16
- package/shared/inline-chunk-html-plugin.js +64 -0
- package/utils/checkRequiredFiles.js +31 -0
- package/utils/clearConsole.js +14 -0
- package/utils/formatWebpackMessages.js +126 -0
- package/webpack.config.dev.js +12 -3
- package/webpack.config.prod.js +7 -6
- package/shared/optimization-split-chunks.js +0 -31
package/bin/sui-bundler-dev.js
CHANGED
|
@@ -8,8 +8,9 @@ process.on('unhandledRejection', err => {
|
|
|
8
8
|
const program = require('commander')
|
|
9
9
|
const path = require('path')
|
|
10
10
|
const WebpackDevServer = require('webpack-dev-server')
|
|
11
|
-
|
|
12
|
-
const
|
|
11
|
+
|
|
12
|
+
const clearConsole = require('../utils/clearConsole')
|
|
13
|
+
const checkRequiredFiles = require('../utils/checkRequiredFiles')
|
|
13
14
|
const {
|
|
14
15
|
choosePort,
|
|
15
16
|
prepareUrls
|
|
@@ -55,9 +56,6 @@ if (!module.parent) {
|
|
|
55
56
|
webpackConfig.context = context || webpackConfig.context
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
// Don't show ugly deprecation warnings that mess with the logging
|
|
59
|
-
process.noDeprecation = true
|
|
60
|
-
|
|
61
59
|
const start = async ({
|
|
62
60
|
config = webpackConfig,
|
|
63
61
|
packagesToLink = program.linkPackage || []
|
|
@@ -85,13 +83,20 @@ const start = async ({
|
|
|
85
83
|
})
|
|
86
84
|
const compiler = createCompiler(nextConfig, urls)
|
|
87
85
|
const serverConfig = createDevServerConfig(nextConfig, urls.lanUrlForConfig)
|
|
88
|
-
const devServer = new WebpackDevServer(
|
|
86
|
+
const devServer = new WebpackDevServer(
|
|
87
|
+
{
|
|
88
|
+
...serverConfig,
|
|
89
|
+
port,
|
|
90
|
+
host: HOST
|
|
91
|
+
},
|
|
92
|
+
compiler
|
|
93
|
+
)
|
|
89
94
|
log.processing('❯ Starting the development server...\n')
|
|
90
|
-
devServer.
|
|
95
|
+
devServer.startCallback(err => {
|
|
91
96
|
if (err) return log.error(err)
|
|
92
97
|
;['SIGINT', 'SIGTERM'].forEach(sig => {
|
|
93
98
|
process.on(sig, () => {
|
|
94
|
-
devServer.
|
|
99
|
+
devServer.stop()
|
|
95
100
|
process.exit()
|
|
96
101
|
})
|
|
97
102
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const webpack = require('webpack')
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const formatWebpackMessages = require('../utils/formatWebpackMessages')
|
|
3
|
+
const clearConsole = require('../utils/clearConsole')
|
|
4
4
|
const log = require('../shared/log')
|
|
5
5
|
|
|
6
6
|
const isInteractive = process.stdout.isTTY
|
|
@@ -1,51 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
2
3
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware')
|
|
3
4
|
const ignoredFiles = require('react-dev-utils/ignoredFiles')
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const {HOST, HTTPS} = process.env
|
|
7
|
+
const protocol = HTTPS === 'true' ? 'https' : 'http'
|
|
8
|
+
const host = HOST || '0.0.0.0'
|
|
7
9
|
|
|
8
|
-
module.exports =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Prevent a WS client from getting injected as we're already including
|
|
24
|
-
// `webpackHotDevClient`.
|
|
25
|
-
injectClient: false,
|
|
26
|
-
// Tell the server at what URL to serve devServer.contentBase static content.
|
|
27
|
-
publicPath: config.output.publicPath,
|
|
28
|
-
// WebpackDevServer is noisy by default so we emit custom message instead
|
|
29
|
-
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
|
|
30
|
-
quiet: true,
|
|
31
|
-
// Reportedly, this avoids CPU overload on some systems.
|
|
32
|
-
watchOptions: {
|
|
33
|
-
ignored: ignoredFiles(config.context)
|
|
10
|
+
module.exports = config => ({
|
|
11
|
+
allowedHosts: 'all',
|
|
12
|
+
client: {
|
|
13
|
+
logging: 'none',
|
|
14
|
+
overlay: {
|
|
15
|
+
errors: true,
|
|
16
|
+
warnings: false
|
|
17
|
+
},
|
|
18
|
+
progress: true
|
|
19
|
+
},
|
|
20
|
+
static: {
|
|
21
|
+
directory: 'public',
|
|
22
|
+
watch: {
|
|
23
|
+
ignored: ignoredFiles(config.context)
|
|
24
|
+
}
|
|
34
25
|
},
|
|
26
|
+
hot: true,
|
|
35
27
|
https: protocol === 'https',
|
|
36
28
|
host,
|
|
37
|
-
overlay: false,
|
|
38
29
|
historyApiFallback: {
|
|
39
30
|
disableDotRule: true
|
|
40
31
|
},
|
|
41
|
-
|
|
42
|
-
before(app) {
|
|
43
|
-
// This lets us open files from the runtime error overlay.
|
|
44
|
-
app.use(errorOverlayMiddleware())
|
|
45
|
-
},
|
|
46
|
-
after(app) {
|
|
32
|
+
onAfterSetupMiddleware(devServer) {
|
|
47
33
|
// This service worker file is effectively a 'no-op' that will reset any
|
|
48
34
|
// previous service worker registered for the same host:port combination.
|
|
49
|
-
app.use(noopServiceWorkerMiddleware(config.output.publicPath))
|
|
35
|
+
devServer.app.use(noopServiceWorkerMiddleware(config.output.publicPath))
|
|
50
36
|
}
|
|
51
37
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.36.0-beta.1",
|
|
4
4
|
"description": "Config-free bundler for ES6 React apps.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sui-bundler": "./bin/sui-bundler.js"
|
|
@@ -21,31 +21,32 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/core": "7.
|
|
24
|
+
"@babel/core": "7.16.0",
|
|
25
25
|
"@s-ui/helpers": "1",
|
|
26
|
-
"autoprefixer": "
|
|
26
|
+
"autoprefixer": "10.4.0",
|
|
27
27
|
"babel-loader": "8.2.3",
|
|
28
28
|
"babel-preset-sui": "3",
|
|
29
29
|
"commander": "6.2.1",
|
|
30
|
-
"css-loader": "
|
|
31
|
-
"css-minimizer-webpack-plugin": "1.1
|
|
32
|
-
"esbuild-loader": "2.
|
|
30
|
+
"css-loader": "6.5.0",
|
|
31
|
+
"css-minimizer-webpack-plugin": "3.1.1",
|
|
32
|
+
"esbuild-loader": "2.16.0",
|
|
33
33
|
"fast-glob": "3.2.7",
|
|
34
|
-
"html-webpack-plugin": "
|
|
35
|
-
"mini-css-extract-plugin": "
|
|
34
|
+
"html-webpack-plugin": "5.5.0",
|
|
35
|
+
"mini-css-extract-plugin": "2.4.3",
|
|
36
36
|
"null-loader": "4.0.1",
|
|
37
|
-
"
|
|
38
|
-
"postcss
|
|
37
|
+
"process": "0.11.10",
|
|
38
|
+
"postcss": "8.3.11",
|
|
39
|
+
"postcss-loader": "6.2.0",
|
|
39
40
|
"react-dev-utils": "11.0.4",
|
|
40
41
|
"rimraf": "3.0.2",
|
|
41
|
-
"sass": "1.
|
|
42
|
-
"sass-loader": "
|
|
42
|
+
"sass": "1.43.4",
|
|
43
|
+
"sass-loader": "12.3.0",
|
|
43
44
|
"super-sass-loader": "0.1",
|
|
44
45
|
"speed-measure-webpack-plugin": "1.5.0",
|
|
45
|
-
"style-loader": "
|
|
46
|
-
"terser-webpack-plugin": "
|
|
47
|
-
"webpack": "
|
|
48
|
-
"webpack-dev-server": "
|
|
46
|
+
"style-loader": "3.3.1",
|
|
47
|
+
"terser-webpack-plugin": "5.2.4",
|
|
48
|
+
"webpack": "5.61.0",
|
|
49
|
+
"webpack-dev-server": "4.4.0",
|
|
49
50
|
"webpack-manifest-plugin": "4.0.2",
|
|
50
51
|
"webpack-node-externals": "3.0.0"
|
|
51
52
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// from: https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/InlineChunkHtmlPlugin.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict'
|
|
11
|
+
|
|
12
|
+
class InlineChunkHtmlPlugin {
|
|
13
|
+
constructor(htmlWebpackPlugin, tests) {
|
|
14
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin
|
|
15
|
+
this.tests = tests
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getInlinedTag(publicPath, assets, tag) {
|
|
19
|
+
if (tag.tagName !== 'script' || !(tag.attributes && tag.attributes.src)) {
|
|
20
|
+
return tag
|
|
21
|
+
}
|
|
22
|
+
const scriptName = publicPath
|
|
23
|
+
? tag.attributes.src.replace(publicPath, '')
|
|
24
|
+
: tag.attributes.src
|
|
25
|
+
if (!this.tests.some(test => scriptName.match(test))) {
|
|
26
|
+
return tag
|
|
27
|
+
}
|
|
28
|
+
const asset = assets[scriptName]
|
|
29
|
+
if (asset == null) {
|
|
30
|
+
return tag
|
|
31
|
+
}
|
|
32
|
+
return {tagName: 'script', innerHTML: asset.source(), closeTag: true}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
apply(compiler) {
|
|
36
|
+
let publicPath = compiler.options.output.publicPath || ''
|
|
37
|
+
if (publicPath && !publicPath.endsWith('/')) {
|
|
38
|
+
publicPath += '/'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
compiler.hooks.compilation.tap('InlineChunkHtmlPlugin', compilation => {
|
|
42
|
+
const tagFunction = tag =>
|
|
43
|
+
this.getInlinedTag(publicPath, compilation.assets, tag)
|
|
44
|
+
|
|
45
|
+
const hooks = this.htmlWebpackPlugin.getHooks(compilation)
|
|
46
|
+
hooks.alterAssetTagGroups.tap('InlineChunkHtmlPlugin', assets => {
|
|
47
|
+
assets.headTags = assets.headTags.map(tagFunction)
|
|
48
|
+
assets.bodyTags = assets.bodyTags.map(tagFunction)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Still emit the runtime chunk for users who do not use our generated
|
|
52
|
+
// index.html file.
|
|
53
|
+
// hooks.afterEmit.tap('InlineChunkHtmlPlugin', () => {
|
|
54
|
+
// Object.keys(compilation.assets).forEach(assetName => {
|
|
55
|
+
// if (this.tests.some(test => assetName.match(test))) {
|
|
56
|
+
// delete compilation.assets[assetName];
|
|
57
|
+
// }
|
|
58
|
+
// });
|
|
59
|
+
// });
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = InlineChunkHtmlPlugin
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/LICENSE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
|
|
11
|
+
function checkRequiredFiles(files) {
|
|
12
|
+
let currentFilePath
|
|
13
|
+
try {
|
|
14
|
+
files.forEach(filePath => {
|
|
15
|
+
currentFilePath = filePath
|
|
16
|
+
fs.accessSync(filePath, fs.F_OK)
|
|
17
|
+
})
|
|
18
|
+
return true
|
|
19
|
+
} catch (err) {
|
|
20
|
+
const dirName = path.dirname(currentFilePath)
|
|
21
|
+
const fileName = path.basename(currentFilePath)
|
|
22
|
+
|
|
23
|
+
console.log('Could not find a required file:')
|
|
24
|
+
console.log(` Name: ${fileName}`)
|
|
25
|
+
console.log(` Searched in: ${dirName}`)
|
|
26
|
+
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = checkRequiredFiles
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/LICENSE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function clearConsole() {
|
|
9
|
+
process.stdout.write(
|
|
10
|
+
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = clearConsole
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/LICENSE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const friendlySyntaxErrorLabel = 'Syntax error:'
|
|
9
|
+
|
|
10
|
+
function isLikelyASyntaxError(message) {
|
|
11
|
+
return message.includes(friendlySyntaxErrorLabel)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Cleans up webpack error messages.
|
|
15
|
+
function formatMessage(message) {
|
|
16
|
+
let lines = []
|
|
17
|
+
|
|
18
|
+
if (typeof message === 'string') {
|
|
19
|
+
lines = message.split('\n')
|
|
20
|
+
} else if ('message' in message) {
|
|
21
|
+
lines = message.message.split('\n')
|
|
22
|
+
} else if (Array.isArray(message)) {
|
|
23
|
+
message.forEach(message => {
|
|
24
|
+
if ('message' in message) {
|
|
25
|
+
lines = message.message.split('\n')
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Strip webpack-added headers off errors/warnings
|
|
31
|
+
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
32
|
+
lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line))
|
|
33
|
+
|
|
34
|
+
// Transform parsing error into syntax error
|
|
35
|
+
// TODO: move this to our ESLint formatter?
|
|
36
|
+
lines = lines.map(line => {
|
|
37
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
|
38
|
+
line
|
|
39
|
+
)
|
|
40
|
+
if (!parsingError) {
|
|
41
|
+
return line
|
|
42
|
+
}
|
|
43
|
+
const [, errorLine, errorColumn, errorMessage] = parsingError
|
|
44
|
+
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
message = lines.join('\n')
|
|
48
|
+
// Smoosh syntax errors (commonly found in CSS)
|
|
49
|
+
message = message.replace(
|
|
50
|
+
/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
|
|
51
|
+
`${friendlySyntaxErrorLabel} $3 ($1:$2)\n`
|
|
52
|
+
)
|
|
53
|
+
// Clean up export errors
|
|
54
|
+
message = message.replace(
|
|
55
|
+
/^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
|
|
56
|
+
`Attempted import error: '$1' is not exported from '$2'.`
|
|
57
|
+
)
|
|
58
|
+
message = message.replace(
|
|
59
|
+
/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
|
|
60
|
+
`Attempted import error: '$2' does not contain a default export (imported as '$1').`
|
|
61
|
+
)
|
|
62
|
+
message = message.replace(
|
|
63
|
+
/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
|
|
64
|
+
`Attempted import error: '$1' is not exported from '$3' (imported as '$2').`
|
|
65
|
+
)
|
|
66
|
+
lines = message.split('\n')
|
|
67
|
+
|
|
68
|
+
// Remove leading newline
|
|
69
|
+
if (lines.length > 2 && lines[1].trim() === '') {
|
|
70
|
+
lines.splice(1, 1)
|
|
71
|
+
}
|
|
72
|
+
// Clean up file name
|
|
73
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1')
|
|
74
|
+
|
|
75
|
+
// Cleans up verbose "module not found" messages for files and packages.
|
|
76
|
+
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
|
77
|
+
lines = [
|
|
78
|
+
lines[0],
|
|
79
|
+
lines[1]
|
|
80
|
+
.replace('Error: ', '')
|
|
81
|
+
.replace('Module not found: Cannot find file:', 'Cannot find file:')
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Add helpful message for users trying to use Sass for the first time
|
|
86
|
+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
87
|
+
lines[1] = 'To import Sass files, you first need to install sass.\n'
|
|
88
|
+
lines[1] +=
|
|
89
|
+
'Run `npm install sass` or `yarn add sass` inside your workspace.'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
message = lines.join('\n')
|
|
93
|
+
// Internal stacks are generally useless so we strip them... with the
|
|
94
|
+
// exception of stacks containing `webpack:` because they're normally
|
|
95
|
+
// from user code generated by webpack. For more information see
|
|
96
|
+
// https://github.com/facebook/create-react-app/pull/1050
|
|
97
|
+
message = message.replace(
|
|
98
|
+
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
|
99
|
+
''
|
|
100
|
+
) // at ... ...:x:y
|
|
101
|
+
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, '') // at <anonymous>
|
|
102
|
+
lines = message.split('\n')
|
|
103
|
+
|
|
104
|
+
// Remove duplicated newlines
|
|
105
|
+
lines = lines.filter(
|
|
106
|
+
(line, index, arr) =>
|
|
107
|
+
index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
// Reassemble the message
|
|
111
|
+
message = lines.join('\n')
|
|
112
|
+
return message.trim()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function formatWebpackMessages(json) {
|
|
116
|
+
const formattedErrors = json.errors.map(formatMessage)
|
|
117
|
+
const formattedWarnings = json.warnings.map(formatMessage)
|
|
118
|
+
const result = {errors: formattedErrors, warnings: formattedWarnings}
|
|
119
|
+
if (result.errors.some(isLikelyASyntaxError)) {
|
|
120
|
+
// If there are any syntax errors, show just them.
|
|
121
|
+
result.errors = result.errors.filter(isLikelyASyntaxError)
|
|
122
|
+
}
|
|
123
|
+
return result
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = formatWebpackMessages
|
package/webpack.config.dev.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
const path = require('path')
|
|
2
4
|
const webpack = require('webpack')
|
|
3
5
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
@@ -16,6 +18,9 @@ const useExperimentalSCSSLoader =
|
|
|
16
18
|
|
|
17
19
|
const smp = new SpeedMeasurePlugin()
|
|
18
20
|
|
|
21
|
+
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
22
|
+
|
|
23
|
+
/** @type {WebpackConfig} */
|
|
19
24
|
const webpackConfig = {
|
|
20
25
|
mode: 'development',
|
|
21
26
|
context: path.resolve(process.env.PWD, 'src'),
|
|
@@ -27,14 +32,15 @@ const webpackConfig = {
|
|
|
27
32
|
extensions: ['.js', '.json'],
|
|
28
33
|
modules: ['node_modules', path.resolve(process.cwd())]
|
|
29
34
|
},
|
|
35
|
+
stats: 'errors-only',
|
|
30
36
|
entry: cleanList([
|
|
31
37
|
require.resolve('react-dev-utils/webpackHotDevClient'),
|
|
32
38
|
MAIN_ENTRY_POINT
|
|
33
39
|
]),
|
|
34
40
|
target: 'web',
|
|
35
|
-
node:
|
|
41
|
+
node: false,
|
|
36
42
|
optimization: {
|
|
37
|
-
|
|
43
|
+
emitOnErrors: false,
|
|
38
44
|
removeAvailableModules: false,
|
|
39
45
|
removeEmptyChunks: false,
|
|
40
46
|
runtimeChunk: true,
|
|
@@ -45,6 +51,9 @@ const webpackConfig = {
|
|
|
45
51
|
publicPath: '/'
|
|
46
52
|
},
|
|
47
53
|
plugins: [
|
|
54
|
+
new webpack.ProvidePlugin({
|
|
55
|
+
process: 'process/browser'
|
|
56
|
+
}),
|
|
48
57
|
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
49
58
|
definePlugin({__DEV__: true}),
|
|
50
59
|
new HtmlWebpackPlugin({
|
|
@@ -104,7 +113,7 @@ const webpackConfig = {
|
|
|
104
113
|
])
|
|
105
114
|
},
|
|
106
115
|
devtool:
|
|
107
|
-
config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev :
|
|
116
|
+
config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
|
package/webpack.config.prod.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
/* eslint-disable no-console */
|
|
2
4
|
const webpack = require('webpack')
|
|
3
5
|
const path = require('path')
|
|
@@ -5,7 +7,7 @@ const path = require('path')
|
|
|
5
7
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
6
8
|
const {WebpackManifestPlugin} = require('webpack-manifest-plugin')
|
|
7
9
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
8
|
-
const InlineChunkHtmlPlugin = require('
|
|
10
|
+
const InlineChunkHtmlPlugin = require('./shared/inline-chunk-html-plugin.js')
|
|
9
11
|
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
|
|
10
12
|
const {
|
|
11
13
|
when,
|
|
@@ -19,7 +21,6 @@ const minifyCss = require('./shared/minify-css')
|
|
|
19
21
|
const definePlugin = require('./shared/define')
|
|
20
22
|
const babelRules = require('./shared/module-rules-babel')
|
|
21
23
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader')
|
|
22
|
-
const {splitChunks} = require('./shared/optimization-split-chunks')
|
|
23
24
|
const {
|
|
24
25
|
extractComments,
|
|
25
26
|
useExperimentalMinifier,
|
|
@@ -40,6 +41,9 @@ const cssFileName = config.onlyHash
|
|
|
40
41
|
|
|
41
42
|
const smp = new SpeedMeasurePlugin()
|
|
42
43
|
|
|
44
|
+
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
45
|
+
|
|
46
|
+
/** @type {WebpackConfig} */
|
|
43
47
|
const webpackConfig = {
|
|
44
48
|
devtool: sourceMap,
|
|
45
49
|
mode: 'production',
|
|
@@ -63,15 +67,12 @@ const webpackConfig = {
|
|
|
63
67
|
publicPath: PUBLIC_PATH
|
|
64
68
|
},
|
|
65
69
|
optimization: {
|
|
66
|
-
// avoid looping over all the modules after the compilation
|
|
67
|
-
checkWasmTypes: false,
|
|
68
70
|
minimize: true,
|
|
69
71
|
minimizer: [
|
|
70
72
|
minifyJs({useExperimentalMinifier, extractComments, sourceMap}),
|
|
71
73
|
minifyCss()
|
|
72
74
|
].filter(Boolean),
|
|
73
|
-
runtimeChunk: true
|
|
74
|
-
splitChunks
|
|
75
|
+
runtimeChunk: true
|
|
75
76
|
},
|
|
76
77
|
plugins: cleanList([
|
|
77
78
|
new webpack.HashedModuleIdsPlugin(),
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const {config} = require('./')
|
|
2
|
-
|
|
3
|
-
const hasToSplitFrameworksOnChunk =
|
|
4
|
-
config.optimizations && config.optimizations.splitFrameworkOnChunk
|
|
5
|
-
|
|
6
|
-
const frameworkSplitChunk = {
|
|
7
|
-
framework: {
|
|
8
|
-
chunks: 'all',
|
|
9
|
-
name: 'framework',
|
|
10
|
-
// This regex ignores nested copies of framework libraries so they're
|
|
11
|
-
// bundled with their issuer: https://github.com/vercel/next.js/pull/9012
|
|
12
|
-
test: /(?<!node_modules.*)[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types|use-subscription)[\\/]/,
|
|
13
|
-
priority: 40,
|
|
14
|
-
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
15
|
-
// becoming a part of the commons chunk)
|
|
16
|
-
enforce: true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.splitChunks = {
|
|
21
|
-
cacheGroups: {
|
|
22
|
-
...(hasToSplitFrameworksOnChunk && frameworkSplitChunk),
|
|
23
|
-
vendor: {
|
|
24
|
-
chunks: 'all',
|
|
25
|
-
name: 'vendor',
|
|
26
|
-
test: 'vendor',
|
|
27
|
-
enforce: true,
|
|
28
|
-
reuseExistingChunk: true
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|