@s-ui/bundler 8.0.0-beta.1 → 8.0.0-beta.5

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 CHANGED
@@ -183,10 +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
186
  }
191
187
  }
192
188
  }
@@ -314,14 +310,6 @@ Different values can be configured for development (`dev`) and production (`prod
314
310
 
315
311
  Check all possible values accepted by webpack in the [devtool webpack docs](https://webpack.js.org/configuration/devtool/#devtool)
316
312
 
317
- ## Optimizations
318
-
319
- You could tweak the performance of your bundle generation by using some flags provided in this config.
320
-
321
- `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.
322
-
323
- `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.
324
-
325
313
  ## Migrations
326
314
 
327
315
  ### Migrate from v7 to v8
@@ -39,9 +39,13 @@ program
39
39
  })
40
40
  .parse(process.argv)
41
41
 
42
- const {clean = false, context} = program
42
+ const {
43
+ clean = false,
44
+ context,
45
+ linkPackage: packagesToLink = []
46
+ } = program.opts()
47
+
43
48
  config.context = context || config.context
44
- const packagesToLink = program.linkPackage || []
45
49
 
46
50
  const nextConfig = packagesToLink.length
47
51
  ? linkLoaderConfigBuilder({
@@ -25,7 +25,8 @@ const linkLoaderConfigBuilder = require('../loaders/linkLoaderConfigBuilder')
25
25
  const log = require('../shared/log')
26
26
 
27
27
  const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000
28
- const HOST = process.env.HOST || '0.0.0.0'
28
+ const {CI = false, HOST = '0.0.0.0'} = process.env
29
+ const DEFAULT_WATCH = !CI
29
30
 
30
31
  if (!module.parent) {
31
32
  program
@@ -43,6 +44,11 @@ if (!module.parent) {
43
44
  },
44
45
  []
45
46
  )
47
+ .option(
48
+ '-w, --watch',
49
+ 'Watch files and restart the server on change',
50
+ DEFAULT_WATCH
51
+ )
46
52
  .on('--help', () => {
47
53
  console.log(' Examples:')
48
54
  console.log('')
@@ -52,13 +58,15 @@ if (!module.parent) {
52
58
  console.log('')
53
59
  })
54
60
  .parse(process.argv)
55
- const {context} = program
61
+
62
+ const {context} = program.opts()
63
+
56
64
  webpackConfig.context = context || webpackConfig.context
57
65
  }
58
66
 
59
67
  const start = async ({
60
68
  config = webpackConfig,
61
- packagesToLink = program.linkPackage || []
69
+ packagesToLink = program.opts().linkPackage || []
62
70
  } = {}) => {
63
71
  clearConsole()
64
72
  // Warn and crash if required files are missing
@@ -78,7 +86,7 @@ const start = async ({
78
86
  const urls = prepareUrls(protocol, HOST, port)
79
87
  const nextConfig = linkLoaderConfigBuilder({
80
88
  config,
81
- linkAll: program.linkAll,
89
+ linkAll: program.opts().linkAll,
82
90
  packagesToLink
83
91
  })
84
92
  const compiler = createCompiler(nextConfig, urls)
@@ -35,7 +35,7 @@ const {
35
35
  path: publicPath,
36
36
  args: [entry],
37
37
  root = false
38
- } = program
38
+ } = program.opts()
39
39
 
40
40
  if (!output) {
41
41
  showError(new Error('--output is mandatory.'), program)
@@ -7,6 +7,14 @@ const {HOST, HTTPS} = process.env
7
7
  const protocol = HTTPS === 'true' ? 'https' : 'http'
8
8
  const host = HOST || '0.0.0.0'
9
9
 
10
+ const getWatchOptions = ({context, watch}) => {
11
+ return watch
12
+ ? {
13
+ ignored: ignoredFiles(context)
14
+ }
15
+ : false
16
+ }
17
+
10
18
  module.exports = config => ({
11
19
  allowedHosts: 'all',
12
20
  client: {
@@ -19,9 +27,7 @@ module.exports = config => ({
19
27
  },
20
28
  static: {
21
29
  directory: 'public',
22
- watch: {
23
- ignored: ignoredFiles(config.context)
24
- }
30
+ watch: getWatchOptions(config)
25
31
  },
26
32
  hot: true,
27
33
  https: protocol === 'https',
@@ -1,7 +1,6 @@
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')
@@ -81,7 +80,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
81
80
  const {rules} = config.module
82
81
  const rulesWithLink = rules.map(rule => {
83
82
  const {use, test: regex} = rule
84
- if (!regex.test('.css') || use === 'null-loader') return rule
83
+ if (!regex.test('.css')) return rule
85
84
 
86
85
  return {
87
86
  ...rule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s-ui/bundler",
3
- "version": "8.0.0-beta.1",
3
+ "version": "8.0.0-beta.5",
4
4
  "description": "Config-free bundler for ES6 React apps.",
5
5
  "bin": {
6
6
  "sui-bundler": "./bin/sui-bundler.js"
@@ -27,14 +27,13 @@
27
27
  "autoprefixer": "10.4.0",
28
28
  "babel-loader": "8.2.3",
29
29
  "babel-preset-sui": "3",
30
- "commander": "6.2.1",
30
+ "commander": "8.3.0",
31
31
  "css-loader": "6.5.1",
32
- "css-minimizer-webpack-plugin": "3.1.1",
32
+ "css-minimizer-webpack-plugin": "3.1.3",
33
33
  "esbuild-loader": "2.16.0",
34
34
  "fast-glob": "3.2.7",
35
35
  "html-webpack-plugin": "5.5.0",
36
36
  "mini-css-extract-plugin": "2.4.4",
37
- "null-loader": "4.0.1",
38
37
  "process": "0.11.10",
39
38
  "postcss": "8.3.11",
40
39
  "postcss-loader": "6.2.0",
@@ -43,9 +42,8 @@
43
42
  "sass": "1.43.4",
44
43
  "speed-measure-webpack-plugin": "1.5.0",
45
44
  "style-loader": "3.3.1",
46
- "terser-webpack-plugin": "5.2.4",
47
- "webpack": "5.61.0",
48
- "webpack-dev-server": "4.4.0",
45
+ "webpack": "5.64.1",
46
+ "webpack-dev-server": "4.5.0",
49
47
  "webpack-manifest-plugin": "4.0.2",
50
48
  "webpack-node-externals": "3.0.0"
51
49
  }
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
11
  exports.sourceMap = (sourcemaps && sourcemaps.prod) || false
@@ -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 terser = ({extractComments, sourceMap}) =>
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, useExperimentalMinifier}) =>
61
- useExperimentalMinifier
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.map(formatMessage)
117
- const formattedWarnings = json.warnings.map(formatMessage)
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.
@@ -44,6 +44,7 @@ const webpackConfig = {
44
44
  ]),
45
45
  target: 'web',
46
46
  optimization: {
47
+ checkWasmTypes: false,
47
48
  emitOnErrors: false,
48
49
  removeAvailableModules: false,
49
50
  removeEmptyChunks: false,
@@ -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
 
@@ -61,11 +57,11 @@ const webpackConfig = {
61
57
  publicPath: PUBLIC_PATH
62
58
  },
63
59
  optimization: {
60
+ checkWasmTypes: false,
64
61
  minimize: true,
65
- minimizer: [
66
- minifyJs({useExperimentalMinifier, extractComments, sourceMap}),
67
- minifyCss()
68
- ].filter(Boolean),
62
+ minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(
63
+ Boolean
64
+ ),
69
65
  runtimeChunk: true
70
66
  },
71
67
  plugins: cleanList([
@@ -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
- use: 'null-loader'
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'])