@s-ui/bundler 7.36.0-beta.1 → 8.0.0-beta.2
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/README.md +4 -15
- package/bin/sui-bundler-build.js +3 -2
- package/loaders/linkLoaderConfigBuilder.js +3 -9
- package/package.json +5 -8
- package/shared/config.js +2 -4
- package/shared/minify-js.js +3 -56
- package/utils/formatWebpackMessages.js +2 -2
- package/webpack.config.dev.js +14 -9
- package/webpack.config.prod.js +9 -24
- package/webpack.config.server.js +9 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# sui-
|
|
1
|
+
# sui-bundler
|
|
2
2
|
|
|
3
3
|
> Config-free bundler for ES6 React apps.
|
|
4
4
|
|
|
@@ -183,11 +183,6 @@ This tool works with zero configuration out the box but you could use some confi
|
|
|
183
183
|
"sourcemaps": {
|
|
184
184
|
"dev": "cheap-module-eval-source-map",
|
|
185
185
|
"prod": "hidden-source-map"
|
|
186
|
-
},
|
|
187
|
-
"optimizations": {
|
|
188
|
-
"splitFrameworkOnChunk": true,
|
|
189
|
-
"useExperimentalMinifier": true,
|
|
190
|
-
"useExperimentalSCSSLoader": true
|
|
191
186
|
}
|
|
192
187
|
}
|
|
193
188
|
}
|
|
@@ -315,17 +310,11 @@ Different values can be configured for development (`dev`) and production (`prod
|
|
|
315
310
|
|
|
316
311
|
Check all possible values accepted by webpack in the [devtool webpack docs](https://webpack.js.org/configuration/devtool/#devtool)
|
|
317
312
|
|
|
318
|
-
##
|
|
319
|
-
|
|
320
|
-
You could tweak the performance of your bundle generation by using some flags provided in this config.
|
|
321
|
-
|
|
322
|
-
`splitFrameworkOnChunk` (default: `false`): Separate in a chunk all the packages related to React. This gives you a separated static hashed file, as the version of React doesn't get often upgraded, and a benefit over HTTP2 connections are you're serving smaller files.
|
|
323
|
-
|
|
324
|
-
`useExperimentalMinifier` (default: `false`): Use `esbuild-loader` to minify JavaScript and CSS instead using `terser` and `css-minimizer-webpack-plugin` in order to boost build time and memory usage.
|
|
313
|
+
## Migrations
|
|
325
314
|
|
|
326
|
-
|
|
315
|
+
### Migrate from v7 to v8
|
|
327
316
|
|
|
328
|
-
|
|
317
|
+
`useExperimentalSCSSLoader` is not used anymore and it will be ignored.
|
|
329
318
|
|
|
330
319
|
### Migrate from v6 to v7
|
|
331
320
|
|
package/bin/sui-bundler-build.js
CHANGED
|
@@ -66,13 +66,14 @@ webpack(nextConfig).run(async (error, stats) => {
|
|
|
66
66
|
|
|
67
67
|
if (stats.hasErrors()) {
|
|
68
68
|
const jsonStats = stats.toJson('errors-only')
|
|
69
|
-
return jsonStats.errors.map(log.error)
|
|
69
|
+
return jsonStats.errors.map(({message}) => log.error(message))
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (stats.hasWarnings()) {
|
|
73
73
|
const jsonStats = stats.toJson('errors-warnings')
|
|
74
74
|
log.warn('Webpack generated the following warnings: ')
|
|
75
|
-
jsonStats.warnings
|
|
75
|
+
log.warn(jsonStats.warnings)
|
|
76
|
+
jsonStats.warnings.map(({message}) => log.warn(message))
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
console.log(`Webpack stats: ${stats}`)
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
const fg = require('fast-glob')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
|
|
4
|
-
const {config} = require('../shared')
|
|
5
4
|
const log = require('../shared/log')
|
|
6
5
|
const {defaultAlias} = require('../shared/resolve-alias')
|
|
7
6
|
const createSassLinkImporter = require('./sassLinkImporter.js')
|
|
8
7
|
|
|
9
|
-
const useExperimentalSCSSLoader =
|
|
10
|
-
config.optimizations && config.optimizations.useExperimentalSCSSLoader
|
|
11
|
-
|
|
12
8
|
const diccFromAbsolutePaths = (paths, init = {}) =>
|
|
13
9
|
paths.reduce((acc, pkg) => {
|
|
14
10
|
const packagePath = path.resolve(pkg)
|
|
@@ -64,14 +60,12 @@ module.exports = ({config, packagesToLink, linkAll}) => {
|
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
|
-
* Create a sass-loader config for scss files that
|
|
63
|
+
* Create a @s-ui/sass-loader config for scss files that
|
|
68
64
|
* are handled by Sass. These are nested modules imported
|
|
69
65
|
* and thus is sass binary which needs a special config for them.
|
|
70
66
|
*/
|
|
71
67
|
const sassLoaderWithLinkImporter = {
|
|
72
|
-
loader:
|
|
73
|
-
? require.resolve('super-sass-loader')
|
|
74
|
-
: require.resolve('sass-loader'),
|
|
68
|
+
loader: require.resolve('@s-ui/sass-loader'),
|
|
75
69
|
options: {
|
|
76
70
|
sassOptions: {
|
|
77
71
|
importer: createSassLinkImporter(entryPoints)
|
|
@@ -86,7 +80,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
|
|
|
86
80
|
const {rules} = config.module
|
|
87
81
|
const rulesWithLink = rules.map(rule => {
|
|
88
82
|
const {use, test: regex} = rule
|
|
89
|
-
if (!regex.test('.css')
|
|
83
|
+
if (!regex.test('.css')) return rule
|
|
90
84
|
|
|
91
85
|
return {
|
|
92
86
|
...rule,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-beta.2",
|
|
4
4
|
"description": "Config-free bundler for ES6 React apps.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sui-bundler": "./bin/sui-bundler.js"
|
|
@@ -23,28 +23,25 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/core": "7.16.0",
|
|
25
25
|
"@s-ui/helpers": "1",
|
|
26
|
+
"@s-ui/sass-loader": "1",
|
|
26
27
|
"autoprefixer": "10.4.0",
|
|
27
28
|
"babel-loader": "8.2.3",
|
|
28
29
|
"babel-preset-sui": "3",
|
|
29
30
|
"commander": "6.2.1",
|
|
30
|
-
"css-loader": "6.5.
|
|
31
|
-
"css-minimizer-webpack-plugin": "3.1.
|
|
31
|
+
"css-loader": "6.5.1",
|
|
32
|
+
"css-minimizer-webpack-plugin": "3.1.3",
|
|
32
33
|
"esbuild-loader": "2.16.0",
|
|
33
34
|
"fast-glob": "3.2.7",
|
|
34
35
|
"html-webpack-plugin": "5.5.0",
|
|
35
|
-
"mini-css-extract-plugin": "2.4.
|
|
36
|
-
"null-loader": "4.0.1",
|
|
36
|
+
"mini-css-extract-plugin": "2.4.4",
|
|
37
37
|
"process": "0.11.10",
|
|
38
38
|
"postcss": "8.3.11",
|
|
39
39
|
"postcss-loader": "6.2.0",
|
|
40
40
|
"react-dev-utils": "11.0.4",
|
|
41
41
|
"rimraf": "3.0.2",
|
|
42
42
|
"sass": "1.43.4",
|
|
43
|
-
"sass-loader": "12.3.0",
|
|
44
|
-
"super-sass-loader": "0.1",
|
|
45
43
|
"speed-measure-webpack-plugin": "1.5.0",
|
|
46
44
|
"style-loader": "3.3.1",
|
|
47
|
-
"terser-webpack-plugin": "5.2.4",
|
|
48
45
|
"webpack": "5.61.0",
|
|
49
46
|
"webpack-dev-server": "4.4.0",
|
|
50
47
|
"webpack-manifest-plugin": "4.0.2",
|
package/shared/config.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
const {
|
|
3
3
|
config: packageJsonConfig = {}
|
|
4
4
|
} = require(`${process.cwd()}/package.json`)
|
|
5
|
-
const {'sui-bundler': config = {}} = packageJsonConfig
|
|
6
5
|
|
|
6
|
+
const {'sui-bundler': config = {}} = packageJsonConfig
|
|
7
7
|
const {extractComments, sourcemaps} = config
|
|
8
8
|
|
|
9
9
|
exports.config = config
|
|
10
|
-
exports.useExperimentalMinifier =
|
|
11
|
-
config.optimizations && config.optimizations.useExperimentalMinifier
|
|
12
10
|
exports.extractComments = extractComments || false
|
|
13
|
-
exports.sourceMap = (sourcemaps && sourcemaps.prod) ||
|
|
11
|
+
exports.sourceMap = (sourcemaps && sourcemaps.prod) || false
|
package/shared/minify-js.js
CHANGED
|
@@ -1,63 +1,10 @@
|
|
|
1
1
|
const {ESBuildMinifyPlugin} = require('esbuild-loader')
|
|
2
|
-
const TerserPlugin = require('terser-webpack-plugin')
|
|
3
|
-
const {CI = false} = process.env
|
|
4
|
-
const CI_PARALLEL_CORES = 2
|
|
5
2
|
|
|
6
|
-
const
|
|
7
|
-
new TerserPlugin({
|
|
8
|
-
extractComments,
|
|
9
|
-
terserOptions: {
|
|
10
|
-
parse: {
|
|
11
|
-
// we want terser to parse ecma 8 code. However, we don't want it
|
|
12
|
-
// to apply any minfication steps that turns valid ecma 5 code
|
|
13
|
-
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
14
|
-
// sections only apply transformations that are ecma 5 safe
|
|
15
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
|
16
|
-
ecma: 8
|
|
17
|
-
},
|
|
18
|
-
compress: {
|
|
19
|
-
ecma: 5,
|
|
20
|
-
warnings: false,
|
|
21
|
-
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
22
|
-
// https://github.com/facebook/create-react-app/issues/2376
|
|
23
|
-
// Pending further investigation:
|
|
24
|
-
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
25
|
-
comparisons: false,
|
|
26
|
-
// Disabled because of an issue with Terser breaking valid code:
|
|
27
|
-
// https://github.com/facebook/create-react-app/issues/5250
|
|
28
|
-
// Pending futher investigation:
|
|
29
|
-
// https://github.com/terser-js/terser/issues/120
|
|
30
|
-
inline: 2
|
|
31
|
-
},
|
|
32
|
-
mangle: {
|
|
33
|
-
safari10: true
|
|
34
|
-
},
|
|
35
|
-
output: {
|
|
36
|
-
ecma: 5,
|
|
37
|
-
comments: false,
|
|
38
|
-
// Turned on because emoji and regex is not minified properly using default
|
|
39
|
-
// https://github.com/facebook/create-react-app/issues/2488
|
|
40
|
-
ascii_only: true
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
// Use multi-process parallel running to improve the build speed
|
|
44
|
-
// For CI: Use only fixed cores as it gives incorrect info and could cause troubles
|
|
45
|
-
// Related: https://github.com/webpack-contrib/terser-webpack-plugin/issues/202
|
|
46
|
-
// If not CI then use os.cpus().length - 1
|
|
47
|
-
parallel: CI ? CI_PARALLEL_CORES : true,
|
|
48
|
-
// Enable file caching
|
|
49
|
-
cache: true,
|
|
50
|
-
// use sourceMap if parameter is provided
|
|
51
|
-
sourceMap: !!sourceMap
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
const esbuild = ({extractComments, sourceMap}) =>
|
|
3
|
+
const esbuild = ({sourceMap}) =>
|
|
55
4
|
new ESBuildMinifyPlugin({
|
|
56
5
|
target: 'es6',
|
|
57
6
|
sourcemap: sourceMap !== 'none' && sourceMap !== false
|
|
58
7
|
})
|
|
59
8
|
|
|
60
|
-
module.exports = ({extractComments, sourceMap
|
|
61
|
-
|
|
62
|
-
? esbuild({extractComments, sourceMap})
|
|
63
|
-
: terser({extractComments, sourceMap})
|
|
9
|
+
module.exports = ({extractComments, sourceMap}) =>
|
|
10
|
+
esbuild({extractComments, sourceMap})
|
|
@@ -113,8 +113,8 @@ function formatMessage(message) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function formatWebpackMessages(json) {
|
|
116
|
-
const formattedErrors = json.errors
|
|
117
|
-
const formattedWarnings = json.warnings
|
|
116
|
+
const formattedErrors = json.errors?.map(formatMessage)
|
|
117
|
+
const formattedWarnings = json.warnings?.map(formatMessage)
|
|
118
118
|
const result = {errors: formattedErrors, warnings: formattedWarnings}
|
|
119
119
|
if (result.errors.some(isLikelyASyntaxError)) {
|
|
120
120
|
// If there are any syntax errors, show just them.
|
package/webpack.config.dev.js
CHANGED
|
@@ -4,6 +4,7 @@ const path = require('path')
|
|
|
4
4
|
const webpack = require('webpack')
|
|
5
5
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
6
6
|
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
|
|
7
|
+
|
|
7
8
|
const definePlugin = require('./shared/define')
|
|
8
9
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader')
|
|
9
10
|
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias')
|
|
@@ -11,10 +12,11 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared')
|
|
|
11
12
|
const {resolveLoader} = require('./shared/resolve-loader')
|
|
12
13
|
|
|
13
14
|
const EXCLUDED_FOLDERS_REGEXP = new RegExp(
|
|
14
|
-
`node_modules(?!${path.sep}@s-ui(${path.sep}
|
|
15
|
+
`node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
|
|
15
16
|
)
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const outputPath = path.join(process.cwd(), 'dist')
|
|
18
|
+
|
|
19
|
+
process.env.NODE_ENV = 'development'
|
|
18
20
|
|
|
19
21
|
const smp = new SpeedMeasurePlugin()
|
|
20
22
|
|
|
@@ -29,8 +31,11 @@ const webpackConfig = {
|
|
|
29
31
|
...defaultAlias,
|
|
30
32
|
...aliasFromConfig
|
|
31
33
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
fallback: {
|
|
35
|
+
fs: false
|
|
36
|
+
},
|
|
37
|
+
modules: ['node_modules', path.resolve(process.cwd())],
|
|
38
|
+
extensions: ['.js', '.json']
|
|
34
39
|
},
|
|
35
40
|
stats: 'errors-only',
|
|
36
41
|
entry: cleanList([
|
|
@@ -38,8 +43,8 @@ const webpackConfig = {
|
|
|
38
43
|
MAIN_ENTRY_POINT
|
|
39
44
|
]),
|
|
40
45
|
target: 'web',
|
|
41
|
-
node: false,
|
|
42
46
|
optimization: {
|
|
47
|
+
checkWasmTypes: false,
|
|
43
48
|
emitOnErrors: false,
|
|
44
49
|
removeAvailableModules: false,
|
|
45
50
|
removeEmptyChunks: false,
|
|
@@ -47,6 +52,7 @@ const webpackConfig = {
|
|
|
47
52
|
splitChunks: false
|
|
48
53
|
},
|
|
49
54
|
output: {
|
|
55
|
+
path: outputPath,
|
|
50
56
|
pathinfo: false,
|
|
51
57
|
publicPath: '/'
|
|
52
58
|
},
|
|
@@ -102,9 +108,7 @@ const webpackConfig = {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
},
|
|
105
|
-
|
|
106
|
-
? require.resolve('super-sass-loader')
|
|
107
|
-
: require.resolve('sass-loader')
|
|
111
|
+
require.resolve('@s-ui/sass-loader')
|
|
108
112
|
])
|
|
109
113
|
},
|
|
110
114
|
when(config['externals-manifest'], () =>
|
|
@@ -112,6 +116,7 @@ const webpackConfig = {
|
|
|
112
116
|
)
|
|
113
117
|
])
|
|
114
118
|
},
|
|
119
|
+
watch: true,
|
|
115
120
|
devtool:
|
|
116
121
|
config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
|
|
117
122
|
}
|
package/webpack.config.prod.js
CHANGED
|
@@ -21,11 +21,7 @@ const minifyCss = require('./shared/minify-css')
|
|
|
21
21
|
const definePlugin = require('./shared/define')
|
|
22
22
|
const babelRules = require('./shared/module-rules-babel')
|
|
23
23
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader')
|
|
24
|
-
const {
|
|
25
|
-
extractComments,
|
|
26
|
-
useExperimentalMinifier,
|
|
27
|
-
sourceMap
|
|
28
|
-
} = require('./shared/config')
|
|
24
|
+
const {extractComments, sourceMap} = require('./shared/config')
|
|
29
25
|
const {aliasFromConfig} = require('./shared/resolve-alias')
|
|
30
26
|
const {resolveLoader} = require('./shared/resolve-loader')
|
|
31
27
|
|
|
@@ -53,13 +49,7 @@ const webpackConfig = {
|
|
|
53
49
|
extensions: ['.js', '.json'],
|
|
54
50
|
modules: ['node_modules', path.resolve(process.cwd())]
|
|
55
51
|
},
|
|
56
|
-
entry:
|
|
57
|
-
? {
|
|
58
|
-
app: MAIN_ENTRY_POINT,
|
|
59
|
-
vendor: config.vendor
|
|
60
|
-
}
|
|
61
|
-
: MAIN_ENTRY_POINT,
|
|
62
|
-
target: 'web',
|
|
52
|
+
entry: MAIN_ENTRY_POINT,
|
|
63
53
|
output: {
|
|
64
54
|
chunkFilename: filename,
|
|
65
55
|
filename,
|
|
@@ -67,15 +57,15 @@ const webpackConfig = {
|
|
|
67
57
|
publicPath: PUBLIC_PATH
|
|
68
58
|
},
|
|
69
59
|
optimization: {
|
|
60
|
+
checkWasmTypes: false,
|
|
70
61
|
minimize: true,
|
|
71
|
-
minimizer: [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
].filter(Boolean),
|
|
62
|
+
minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(
|
|
63
|
+
Boolean
|
|
64
|
+
),
|
|
75
65
|
runtimeChunk: true
|
|
76
66
|
},
|
|
77
67
|
plugins: cleanList([
|
|
78
|
-
new webpack.HashedModuleIdsPlugin(),
|
|
68
|
+
new webpack.ids.HashedModuleIdsPlugin(),
|
|
79
69
|
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
80
70
|
definePlugin(),
|
|
81
71
|
new MiniCssExtractPlugin({
|
|
@@ -127,7 +117,7 @@ const webpackConfig = {
|
|
|
127
117
|
}
|
|
128
118
|
}
|
|
129
119
|
},
|
|
130
|
-
require.resolve('sass-loader')
|
|
120
|
+
require.resolve('@s-ui/sass-loader')
|
|
131
121
|
])
|
|
132
122
|
},
|
|
133
123
|
when(config['externals-manifest'], () =>
|
|
@@ -135,12 +125,7 @@ const webpackConfig = {
|
|
|
135
125
|
)
|
|
136
126
|
])
|
|
137
127
|
},
|
|
138
|
-
resolveLoader
|
|
139
|
-
node: {
|
|
140
|
-
fs: 'empty',
|
|
141
|
-
net: 'empty',
|
|
142
|
-
tls: 'empty'
|
|
143
|
-
}
|
|
128
|
+
resolveLoader
|
|
144
129
|
}
|
|
145
130
|
|
|
146
131
|
module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
|
package/webpack.config.server.js
CHANGED
|
@@ -10,6 +10,9 @@ const {resolveLoader} = require('./shared/resolve-loader')
|
|
|
10
10
|
|
|
11
11
|
const filename = '[name].[chunkhash:8].js'
|
|
12
12
|
|
|
13
|
+
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
14
|
+
|
|
15
|
+
/** @type {WebpackConfig} */
|
|
13
16
|
const webpackConfig = {
|
|
14
17
|
context: path.resolve(process.cwd(), 'src'),
|
|
15
18
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
@@ -37,9 +40,12 @@ const webpackConfig = {
|
|
|
37
40
|
rules: cleanList([
|
|
38
41
|
babelRules,
|
|
39
42
|
{
|
|
40
|
-
// ignore css/scss require/imports files in the server
|
|
41
|
-
test: /\.s?css$/,
|
|
42
|
-
|
|
43
|
+
// ignore css/scss/svg require/imports files in the server
|
|
44
|
+
test: [/\.s?css$/, /\.svg$/],
|
|
45
|
+
type: 'asset/inline',
|
|
46
|
+
generator: {
|
|
47
|
+
dataUrl: () => ''
|
|
48
|
+
}
|
|
43
49
|
},
|
|
44
50
|
when(config['externals-manifest'], () =>
|
|
45
51
|
manifestLoaderRules(config['externals-manifest'])
|