@s-ui/bundler 8.0.0-beta.0 → 8.0.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.
@@ -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,28 @@
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
 
20
19
  process.env.NODE_ENV = 'development'
21
20
 
21
+ const smp = new SpeedMeasurePlugin()
22
+
23
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
24
+
25
+ /** @type {WebpackConfig} */
22
26
  const webpackConfig = {
23
27
  mode: 'development',
24
28
  context: path.resolve(process.env.PWD, 'src'),
@@ -30,11 +34,13 @@ const webpackConfig = {
30
34
  fallback: {
31
35
  fs: false
32
36
  },
37
+ modules: ['node_modules', path.resolve(process.cwd())],
33
38
  extensions: ['.js', '.json']
34
39
  },
40
+ stats: 'errors-only',
35
41
  entry: cleanList([
36
- MAIN_ENTRY_POINT,
37
- require.resolve('webpack-plugin-serve/client')
42
+ require.resolve('react-dev-utils/webpackHotDevClient'),
43
+ MAIN_ENTRY_POINT
38
44
  ]),
39
45
  target: 'web',
40
46
  optimization: {
@@ -50,22 +56,15 @@ const webpackConfig = {
50
56
  publicPath: '/'
51
57
  },
52
58
  plugins: [
59
+ new webpack.ProvidePlugin({
60
+ process: 'process/browser'
61
+ }),
53
62
  new webpack.EnvironmentPlugin(envVars(config.env)),
54
63
  definePlugin({__DEV__: true}),
55
64
  new HtmlWebpackPlugin({
56
65
  template: './index.html',
57
66
  inject: true,
58
67
  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
68
  })
70
69
  ],
71
70
  resolveLoader,
@@ -108,7 +107,7 @@ const webpackConfig = {
108
107
  }
109
108
  }
110
109
  },
111
- require.resolve('sass-loader')
110
+ require.resolve('@s-ui/sass-loader')
112
111
  ])
113
112
  },
114
113
  when(config['externals-manifest'], () =>
@@ -121,4 +120,4 @@ const webpackConfig = {
121
120
  config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
122
121
  }
123
122
 
124
- module.exports = webpackConfig
123
+ 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,8 +21,11 @@ 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 {extractComments, sourceMap} = require('./shared/config')
24
+ const {
25
+ extractComments,
26
+ useExperimentalMinifier,
27
+ sourceMap
28
+ } = require('./shared/config')
24
29
  const {aliasFromConfig} = require('./shared/resolve-alias')
25
30
  const {resolveLoader} = require('./shared/resolve-loader')
26
31
 
@@ -34,19 +39,19 @@ const cssFileName = config.onlyHash
34
39
  ? '[contenthash:8].css'
35
40
  : '[name].[contenthash:8].css'
36
41
 
37
- module.exports = {
38
- target: ['web', 'es5'],
42
+ const smp = new SpeedMeasurePlugin()
43
+
44
+ /** @typedef {import('webpack').Configuration} WebpackConfig */
45
+
46
+ /** @type {WebpackConfig} */
47
+ const webpackConfig = {
39
48
  devtool: sourceMap,
40
49
  mode: 'production',
41
50
  context: path.resolve(process.cwd(), 'src'),
42
51
  resolve: {
43
52
  alias: {...aliasFromConfig},
44
53
  extensions: ['.js', '.json'],
45
- fallback: {
46
- fs: 'empty',
47
- net: 'empty',
48
- tls: 'empty'
49
- }
54
+ modules: ['node_modules', path.resolve(process.cwd())]
50
55
  },
51
56
  entry: MAIN_ENTRY_POINT,
52
57
  output: {
@@ -56,14 +61,15 @@ module.exports = {
56
61
  publicPath: PUBLIC_PATH
57
62
  },
58
63
  optimization: {
59
- // avoid looping over all the modules after the compilation
60
- checkWasmTypes: false,
61
64
  minimize: true,
62
- minimizer: [minifyJs({extractComments}), minifyCss()],
63
- runtimeChunk: true,
64
- splitChunks
65
+ minimizer: [
66
+ minifyJs({useExperimentalMinifier, extractComments, sourceMap}),
67
+ minifyCss()
68
+ ].filter(Boolean),
69
+ runtimeChunk: true
65
70
  },
66
71
  plugins: cleanList([
72
+ new webpack.ids.HashedModuleIdsPlugin(),
67
73
  new webpack.EnvironmentPlugin(envVars(config.env)),
68
74
  definePlugin(),
69
75
  new MiniCssExtractPlugin({
@@ -115,7 +121,7 @@ module.exports = {
115
121
  }
116
122
  }
117
123
  },
118
- require.resolve('sass-loader')
124
+ require.resolve('@s-ui/sass-loader')
119
125
  ])
120
126
  },
121
127
  when(config['externals-manifest'], () =>
@@ -125,3 +131,5 @@ module.exports = {
125
131
  },
126
132
  resolveLoader
127
133
  }
134
+
135
+ module.exports = config.measure ? smp.wrap(webpackConfig) : webpackConfig
@@ -15,7 +15,8 @@ const webpackConfig = {
15
15
  mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
16
16
  resolve: {
17
17
  alias: {...aliasFromConfig},
18
- extensions: ['.js', '.json']
18
+ extensions: ['.js', '.json'],
19
+ modules: ['node_modules', path.resolve(process.cwd())]
19
20
  },
20
21
  entry: './server.js',
21
22
  target: 'node',