@s-ui/bundler 8.0.0-beta.0 → 8.0.0-beta.12

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.
@@ -1,47 +1,10 @@
1
- const TerserPlugin = require('terser-webpack-plugin')
2
- const {CI = false} = process.env
3
- const CI_PARALLEL_CORES = 2
1
+ const {ESBuildMinifyPlugin} = require('esbuild-loader')
4
2
 
5
- module.exports = ({extractComments}) =>
6
- new TerserPlugin({
7
- extractComments,
8
- terserOptions: {
9
- parse: {
10
- // we want terser to parse ecma 8 code. However, we don't want it
11
- // to apply any minfication steps that turns valid ecma 5 code
12
- // into invalid ecma 5 code. This is why the 'compress' and 'output'
13
- // sections only apply transformations that are ecma 5 safe
14
- // https://github.com/facebook/create-react-app/pull/4234
15
- ecma: 8
16
- },
17
- compress: {
18
- ecma: 5,
19
- warnings: false,
20
- // Disabled because of an issue with Uglify breaking seemingly valid code:
21
- // https://github.com/facebook/create-react-app/issues/2376
22
- // Pending further investigation:
23
- // https://github.com/mishoo/UglifyJS2/issues/2011
24
- comparisons: false,
25
- // Disabled because of an issue with Terser breaking valid code:
26
- // https://github.com/facebook/create-react-app/issues/5250
27
- // Pending futher investigation:
28
- // https://github.com/terser-js/terser/issues/120
29
- inline: 2
30
- },
31
- mangle: {
32
- safari10: true
33
- },
34
- output: {
35
- ecma: 5,
36
- comments: false,
37
- // Turned on because emoji and regex is not minified properly using default
38
- // https://github.com/facebook/create-react-app/issues/2488
39
- ascii_only: true
40
- }
41
- },
42
- // Use multi-process parallel running to improve the build speed
43
- // For CI: Use only fixed cores as it gives incorrect info and could cause troubles
44
- // Related: https://github.com/webpack-contrib/terser-webpack-plugin/issues/202
45
- // If not CI then use os.cpus().length - 1
46
- parallel: CI ? CI_PARALLEL_CORES : true
3
+ const esbuild = ({sourceMap}) =>
4
+ new ESBuildMinifyPlugin({
5
+ target: 'es6',
6
+ sourcemap: sourceMap !== 'none' && sourceMap !== false
47
7
  })
8
+
9
+ module.exports = ({extractComments, sourceMap}) =>
10
+ esbuild({extractComments, sourceMap})
@@ -8,6 +8,8 @@ module.exports = {
8
8
  {
9
9
  loader: require.resolve('babel-loader'),
10
10
  options: {
11
+ cacheDirectory: true,
12
+ cacheCompression: false,
11
13
  babelrc: false,
12
14
  compact: true,
13
15
  presets: [
@@ -12,6 +12,7 @@ const {PWD} = process.env
12
12
  const defaultPackagesToAlias = [
13
13
  'react',
14
14
  'react-router-dom',
15
+ '@s-ui/pde',
15
16
  '@s-ui/react-context',
16
17
  '@s-ui/react-router'
17
18
  ]
@@ -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
@@ -1,24 +1,30 @@
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
- const {WebpackPluginServe: Serve} = require('webpack-plugin-serve')
6
+ const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
5
7
 
6
8
  const definePlugin = require('./shared/define')
7
9
  const manifestLoaderRules = require('./shared/module-rules-manifest-loader')
8
10
  const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias')
9
-
10
11
  const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared')
11
12
  const {resolveLoader} = require('./shared/resolve-loader')
12
- const getPort = require('get-port')
13
13
 
14
14
  const EXCLUDED_FOLDERS_REGEXP = new RegExp(
15
- `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)`
16
16
  )
17
- const host = process.env.HOST || '0.0.0.0'
18
17
  const outputPath = path.join(process.cwd(), 'dist')
19
18
 
19
+ const {CI = false} = process.env
20
+
20
21
  process.env.NODE_ENV = 'development'
21
22
 
23
+ const smp = new SpeedMeasurePlugin()
24
+
25
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
26
+
27
+ /** @type {WebpackConfig} */
22
28
  const webpackConfig = {
23
29
  mode: 'development',
24
30
  context: path.resolve(process.env.PWD, 'src'),
@@ -30,14 +36,17 @@ const webpackConfig = {
30
36
  fallback: {
31
37
  fs: false
32
38
  },
39
+ modules: ['node_modules', path.resolve(process.cwd())],
33
40
  extensions: ['.js', '.json']
34
41
  },
42
+ stats: 'errors-only',
35
43
  entry: cleanList([
36
- MAIN_ENTRY_POINT,
37
- require.resolve('webpack-plugin-serve/client')
44
+ require.resolve('react-dev-utils/webpackHotDevClient'),
45
+ MAIN_ENTRY_POINT
38
46
  ]),
39
47
  target: 'web',
40
48
  optimization: {
49
+ checkWasmTypes: false,
41
50
  emitOnErrors: false,
42
51
  removeAvailableModules: false,
43
52
  removeEmptyChunks: false,
@@ -50,22 +59,15 @@ const webpackConfig = {
50
59
  publicPath: '/'
51
60
  },
52
61
  plugins: [
62
+ new webpack.ProvidePlugin({
63
+ process: 'process/browser'
64
+ }),
53
65
  new webpack.EnvironmentPlugin(envVars(config.env)),
54
66
  definePlugin({__DEV__: true}),
55
67
  new HtmlWebpackPlugin({
56
68
  template: './index.html',
57
69
  inject: true,
58
70
  env: process.env
59
- }),
60
- new Serve({
61
- compress: true,
62
- historyFallback: true,
63
- host,
64
- hmr: false,
65
- liveReload: true,
66
- open: true,
67
- port: getPort({port: 3000}),
68
- static: [outputPath]
69
71
  })
70
72
  ],
71
73
  resolveLoader,
@@ -108,7 +110,7 @@ const webpackConfig = {
108
110
  }
109
111
  }
110
112
  },
111
- require.resolve('sass-loader')
113
+ require.resolve('@s-ui/sass-loader')
112
114
  ])
113
115
  },
114
116
  when(config['externals-manifest'], () =>
@@ -116,9 +118,9 @@ const webpackConfig = {
116
118
  )
117
119
  ])
118
120
  },
119
- watch: true,
121
+ watch: !CI,
120
122
  devtool:
121
123
  config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
122
124
  }
123
125
 
124
- module.exports = webpackConfig
126
+ module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
@@ -1,5 +1,6 @@
1
1
  const webpack = require('webpack')
2
2
  const {cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index')
3
+ const path = require('path')
3
4
  const minifyJs = require('./shared/minify-js')
4
5
  const definePlugin = require('./shared/define')
5
6
  const babelRules = require('./shared/module-rules-babel')
@@ -12,7 +13,8 @@ module.exports = {
12
13
  alias: {
13
14
  ...aliasFromConfig
14
15
  },
15
- extensions: ['.js', '.json']
16
+ extensions: ['.js', '.json'],
17
+ modules: ['node_modules', path.resolve(process.cwd())]
16
18
  },
17
19
  entry: config.vendor
18
20
  ? {
@@ -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,8 +7,8 @@ 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('./plugins/InlineChunkHtmlPlugin')
9
-
10
+ const InlineChunkHtmlPlugin = require('./shared/inline-chunk-html-plugin.js')
11
+ const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
10
12
  const {
11
13
  when,
12
14
  cleanList,
@@ -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 {extractComments, sourceMap} = require('./shared/config')
24
25
  const {aliasFromConfig} = require('./shared/resolve-alias')
25
26
  const {resolveLoader} = require('./shared/resolve-loader')
@@ -34,18 +35,23 @@ const cssFileName = config.onlyHash
34
35
  ? '[contenthash:8].css'
35
36
  : '[name].[contenthash:8].css'
36
37
 
37
- module.exports = {
38
- target: ['web', 'es5'],
38
+ const smp = new SpeedMeasurePlugin()
39
+
40
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
41
+
42
+ /** @type {WebpackConfig} */
43
+ const webpackConfig = {
39
44
  devtool: sourceMap,
40
45
  mode: 'production',
41
46
  context: path.resolve(process.cwd(), 'src'),
42
47
  resolve: {
43
48
  alias: {...aliasFromConfig},
44
49
  extensions: ['.js', '.json'],
50
+ modules: ['node_modules', path.resolve(process.cwd())],
45
51
  fallback: {
46
- fs: 'empty',
47
- net: 'empty',
48
- tls: 'empty'
52
+ assert: false,
53
+ fs: false,
54
+ path: false
49
55
  }
50
56
  },
51
57
  entry: MAIN_ENTRY_POINT,
@@ -56,14 +62,15 @@ module.exports = {
56
62
  publicPath: PUBLIC_PATH
57
63
  },
58
64
  optimization: {
59
- // avoid looping over all the modules after the compilation
60
65
  checkWasmTypes: false,
61
66
  minimize: true,
62
- minimizer: [minifyJs({extractComments}), minifyCss()],
63
- runtimeChunk: true,
64
- splitChunks
67
+ minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(
68
+ Boolean
69
+ ),
70
+ runtimeChunk: true
65
71
  },
66
72
  plugins: cleanList([
73
+ new webpack.ids.HashedModuleIdsPlugin(),
67
74
  new webpack.EnvironmentPlugin(envVars(config.env)),
68
75
  definePlugin(),
69
76
  new MiniCssExtractPlugin({
@@ -115,7 +122,7 @@ module.exports = {
115
122
  }
116
123
  }
117
124
  },
118
- require.resolve('sass-loader')
125
+ require.resolve('@s-ui/sass-loader')
119
126
  ])
120
127
  },
121
128
  when(config['externals-manifest'], () =>
@@ -125,3 +132,5 @@ module.exports = {
125
132
  },
126
133
  resolveLoader
127
134
  }
135
+
136
+ module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
@@ -10,12 +10,16 @@ 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',
16
19
  resolve: {
17
20
  alias: {...aliasFromConfig},
18
- extensions: ['.js', '.json']
21
+ extensions: ['.js', '.json'],
22
+ modules: ['node_modules', path.resolve(process.cwd())]
19
23
  },
20
24
  entry: './server.js',
21
25
  target: 'node',
@@ -36,9 +40,12 @@ const webpackConfig = {
36
40
  rules: cleanList([
37
41
  babelRules,
38
42
  {
39
- // ignore css/scss require/imports files in the server
40
- test: /\.s?css$/,
41
- 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
+ }
42
49
  },
43
50
  when(config['externals-manifest'], () =>
44
51
  manifestLoaderRules(config['externals-manifest'])