@s-ui/bundler 7.36.0 → 8.0.0-beta.3

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
@@ -1,4 +1,4 @@
1
- # sui-bunder
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
- ## Optimizations
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
- `useExperimentalSCSSLoader` (default: `false`): Use [fast-sass-loader](https://github.com/yibn2008/fast-sass-loader) (currently a fork of it [super-sass-loader](https://github.com/andresz1/super-sass-loader)) instead of `sass-loader` (available in development only)
315
+ ### Migrate from v7 to v8
327
316
 
328
- ## Migrations
317
+ `useExperimentalSCSSLoader` is not used anymore and it will be ignored.
329
318
 
330
319
  ### Migrate from v6 to v7
331
320
 
@@ -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.map(log.warn)
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: useExperimentalSCSSLoader
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') || use === 'null-loader') return rule
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": "7.36.0",
3
+ "version": "8.0.0-beta.3",
4
4
  "description": "Config-free bundler for ES6 React apps.",
5
5
  "bin": {
6
6
  "sui-bundler": "./bin/sui-bundler.js"
@@ -23,29 +23,27 @@
23
23
  "dependencies": {
24
24
  "@babel/core": "7.16.0",
25
25
  "@s-ui/helpers": "1",
26
- "autoprefixer": "9.8.6",
26
+ "@s-ui/sass-loader": "1",
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": "4.3.0",
31
- "css-minimizer-webpack-plugin": "1.1.5",
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
- "html-webpack-plugin": "4.5.0",
35
- "mini-css-extract-plugin": "1.6.0",
36
- "null-loader": "4.0.1",
37
- "postcss": "7.0.35",
38
- "postcss-loader": "4.1.0",
35
+ "html-webpack-plugin": "5.5.0",
36
+ "mini-css-extract-plugin": "2.4.4",
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.43.3",
42
- "sass-loader": "10.1.0",
43
- "super-sass-loader": "0.1",
42
+ "sass": "1.43.4",
44
43
  "speed-measure-webpack-plugin": "1.5.0",
45
- "style-loader": "2.0.0",
46
- "terser-webpack-plugin": "4.2.2",
47
- "webpack": "4.46.0",
48
- "webpack-dev-server": "4.3.1",
44
+ "style-loader": "3.3.1",
45
+ "webpack": "5.61.0",
46
+ "webpack-dev-server": "4.4.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
- exports.sourceMap = (sourcemaps && sourcemaps.prod) || 'none'
11
+ exports.sourceMap = (sourcemaps && sourcemaps.prod) || false
@@ -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
@@ -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.
@@ -1,7 +1,10 @@
1
+ // @ts-check
2
+
1
3
  const path = require('path')
2
4
  const webpack = require('webpack')
3
5
  const HtmlWebpackPlugin = require('html-webpack-plugin')
4
6
  const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
7
+
5
8
  const definePlugin = require('./shared/define')
6
9
  const manifestLoaderRules = require('./shared/module-rules-manifest-loader')
7
10
  const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias')
@@ -9,13 +12,17 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared')
9
12
  const {resolveLoader} = require('./shared/resolve-loader')
10
13
 
11
14
  const EXCLUDED_FOLDERS_REGEXP = new RegExp(
12
- `node_modules(?!${path.sep}@s-ui(${path.sep}svg|${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
15
+ `node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
13
16
  )
14
- const useExperimentalSCSSLoader =
15
- config.optimizations && config.optimizations.useExperimentalSCSSLoader
17
+ const outputPath = path.join(process.cwd(), 'dist')
18
+
19
+ process.env.NODE_ENV = 'development'
16
20
 
17
21
  const smp = new SpeedMeasurePlugin()
18
22
 
23
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
24
+
25
+ /** @type {WebpackConfig} */
19
26
  const webpackConfig = {
20
27
  mode: 'development',
21
28
  context: path.resolve(process.env.PWD, 'src'),
@@ -24,8 +31,11 @@ const webpackConfig = {
24
31
  ...defaultAlias,
25
32
  ...aliasFromConfig
26
33
  },
27
- extensions: ['.js', '.json'],
28
- modules: ['node_modules', path.resolve(process.cwd())]
34
+ fallback: {
35
+ fs: false
36
+ },
37
+ modules: ['node_modules', path.resolve(process.cwd())],
38
+ extensions: ['.js', '.json']
29
39
  },
30
40
  stats: 'errors-only',
31
41
  entry: cleanList([
@@ -33,19 +43,23 @@ const webpackConfig = {
33
43
  MAIN_ENTRY_POINT
34
44
  ]),
35
45
  target: 'web',
36
- node: {fs: 'empty'},
37
46
  optimization: {
38
- noEmitOnErrors: true,
47
+ checkWasmTypes: false,
48
+ emitOnErrors: false,
39
49
  removeAvailableModules: false,
40
50
  removeEmptyChunks: false,
41
51
  runtimeChunk: true,
42
52
  splitChunks: false
43
53
  },
44
54
  output: {
55
+ path: outputPath,
45
56
  pathinfo: false,
46
57
  publicPath: '/'
47
58
  },
48
59
  plugins: [
60
+ new webpack.ProvidePlugin({
61
+ process: 'process/browser'
62
+ }),
49
63
  new webpack.EnvironmentPlugin(envVars(config.env)),
50
64
  definePlugin({__DEV__: true}),
51
65
  new HtmlWebpackPlugin({
@@ -94,9 +108,7 @@ const webpackConfig = {
94
108
  }
95
109
  }
96
110
  },
97
- useExperimentalSCSSLoader
98
- ? require.resolve('super-sass-loader')
99
- : require.resolve('sass-loader')
111
+ require.resolve('@s-ui/sass-loader')
100
112
  ])
101
113
  },
102
114
  when(config['externals-manifest'], () =>
@@ -104,8 +116,9 @@ const webpackConfig = {
104
116
  )
105
117
  ])
106
118
  },
119
+ watch: true,
107
120
  devtool:
108
- config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : 'none'
121
+ config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
109
122
  }
110
123
 
111
124
  module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
@@ -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('react-dev-utils/InlineChunkHtmlPlugin')
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,12 +21,7 @@ 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
- const {
24
- extractComments,
25
- useExperimentalMinifier,
26
- sourceMap
27
- } = require('./shared/config')
24
+ const {extractComments, sourceMap} = require('./shared/config')
28
25
  const {aliasFromConfig} = require('./shared/resolve-alias')
29
26
  const {resolveLoader} = require('./shared/resolve-loader')
30
27
 
@@ -40,6 +37,9 @@ const cssFileName = config.onlyHash
40
37
 
41
38
  const smp = new SpeedMeasurePlugin()
42
39
 
40
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
41
+
42
+ /** @type {WebpackConfig} */
43
43
  const webpackConfig = {
44
44
  devtool: sourceMap,
45
45
  mode: 'production',
@@ -49,13 +49,7 @@ const webpackConfig = {
49
49
  extensions: ['.js', '.json'],
50
50
  modules: ['node_modules', path.resolve(process.cwd())]
51
51
  },
52
- entry: config.vendor
53
- ? {
54
- app: MAIN_ENTRY_POINT,
55
- vendor: config.vendor
56
- }
57
- : MAIN_ENTRY_POINT,
58
- target: 'web',
52
+ entry: MAIN_ENTRY_POINT,
59
53
  output: {
60
54
  chunkFilename: filename,
61
55
  filename,
@@ -63,18 +57,15 @@ const webpackConfig = {
63
57
  publicPath: PUBLIC_PATH
64
58
  },
65
59
  optimization: {
66
- // avoid looping over all the modules after the compilation
67
60
  checkWasmTypes: false,
68
61
  minimize: true,
69
- minimizer: [
70
- minifyJs({useExperimentalMinifier, extractComments, sourceMap}),
71
- minifyCss()
72
- ].filter(Boolean),
73
- runtimeChunk: true,
74
- splitChunks
62
+ minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(
63
+ Boolean
64
+ ),
65
+ runtimeChunk: true
75
66
  },
76
67
  plugins: cleanList([
77
- new webpack.HashedModuleIdsPlugin(),
68
+ new webpack.ids.HashedModuleIdsPlugin(),
78
69
  new webpack.EnvironmentPlugin(envVars(config.env)),
79
70
  definePlugin(),
80
71
  new MiniCssExtractPlugin({
@@ -126,7 +117,7 @@ const webpackConfig = {
126
117
  }
127
118
  }
128
119
  },
129
- require.resolve('sass-loader')
120
+ require.resolve('@s-ui/sass-loader')
130
121
  ])
131
122
  },
132
123
  when(config['externals-manifest'], () =>
@@ -134,12 +125,7 @@ const webpackConfig = {
134
125
  )
135
126
  ])
136
127
  },
137
- resolveLoader,
138
- node: {
139
- fs: 'empty',
140
- net: 'empty',
141
- tls: 'empty'
142
- }
128
+ resolveLoader
143
129
  }
144
130
 
145
131
  module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
@@ -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'])
@@ -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
- }