@s-ui/bundler 9.43.0-beta.0 → 9.43.0-typescript.0
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/bin/sui-bundler-build.js +0 -9
- package/bin/sui-bundler-dev.js +1 -6
- package/bin/sui-bundler-lib.js +3 -12
- package/loaders/linkLoaderConfigBuilder.js +1 -1
- package/package.json +9 -6
- package/scripts/postinstall.js +53 -0
- package/shared/define.js +19 -4
- package/shared/index.js +1 -1
- package/shared/module-rules-compiler.js +68 -0
- package/shared/resolve-alias.js +18 -6
- package/tsconfig.json +3 -0
- package/utils/webpackHotDevClient.js +253 -0
- package/webpack.config.dev.js +9 -13
- package/webpack.config.lib.js +2 -2
- package/webpack.config.prod.js +3 -3
- package/webpack.config.server.js +3 -3
- package/shared/module-rules-babel.js +0 -39
package/bin/sui-bundler-build.js
CHANGED
|
@@ -19,7 +19,6 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
|
19
19
|
|
|
20
20
|
program
|
|
21
21
|
.option('-C, --clean', 'Remove public folder before create a new one')
|
|
22
|
-
.option('-S, --save-stats', 'Save stats.json in public folder')
|
|
23
22
|
.option(
|
|
24
23
|
'-l, --link-package [package]',
|
|
25
24
|
'Replace each occurrence of this package with an absolute path to this folder',
|
|
@@ -44,7 +43,6 @@ program
|
|
|
44
43
|
const {
|
|
45
44
|
clean = false,
|
|
46
45
|
context,
|
|
47
|
-
saveStats,
|
|
48
46
|
linkPackage: packagesToLink = []
|
|
49
47
|
} = program.opts()
|
|
50
48
|
|
|
@@ -90,13 +88,6 @@ compiler.run(async (error, stats) => {
|
|
|
90
88
|
|
|
91
89
|
console.log(`Webpack stats: ${stats}`)
|
|
92
90
|
|
|
93
|
-
if (saveStats) {
|
|
94
|
-
const filePath = `${process.cwd()}/public/stats.json`
|
|
95
|
-
fs.writeFileSync(filePath, JSON.stringify(stats.toJson(), null, 2), {
|
|
96
|
-
encoding: 'utf8'
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
91
|
const offlinePath = path.join(process.cwd(), 'src', 'offline.html')
|
|
101
92
|
const offlinePageExists = fs.existsSync(offlinePath)
|
|
102
93
|
const {offline: offlineConfig = {}} = projectConfig
|
package/bin/sui-bundler-dev.js
CHANGED
|
@@ -67,12 +67,7 @@ const start = async ({
|
|
|
67
67
|
} = {}) => {
|
|
68
68
|
clearConsole()
|
|
69
69
|
// Warn and crash if required files are missing
|
|
70
|
-
if (
|
|
71
|
-
!checkRequiredFiles([
|
|
72
|
-
path.join(config.context, 'index.html'),
|
|
73
|
-
path.join(config.context, 'app.js')
|
|
74
|
-
])
|
|
75
|
-
) {
|
|
70
|
+
if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
|
|
76
71
|
log.error(
|
|
77
72
|
`✖ Required files are missing, create and index.html and app.js inside your src folder.`
|
|
78
73
|
)
|
package/bin/sui-bundler-lib.js
CHANGED
|
@@ -73,18 +73,7 @@ log.processing('Generating minified bundle...')
|
|
|
73
73
|
webpack(webpackConfig).run((error, stats) => {
|
|
74
74
|
if (error) {
|
|
75
75
|
showError(error, program)
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (stats.hasErrors()) {
|
|
80
|
-
const jsonStats = stats.toJson('errors-warnings')
|
|
81
|
-
jsonStats.errors?.forEach(error => log.error(error.message))
|
|
82
|
-
process.exit(1)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (stats.hasWarnings()) {
|
|
86
|
-
const jsonStats = stats.toJson('errors-warnings')
|
|
87
|
-
jsonStats.warnings?.forEach(warning => log.warn(warning.message))
|
|
76
|
+
return 1
|
|
88
77
|
}
|
|
89
78
|
|
|
90
79
|
if (stats.hasErrors() || stats.hasWarnings()) {
|
|
@@ -97,4 +86,6 @@ webpack(webpackConfig).run((error, stats) => {
|
|
|
97
86
|
log.success(
|
|
98
87
|
`Your library is compiled in production mode in: \n${outputFolder}`
|
|
99
88
|
)
|
|
89
|
+
|
|
90
|
+
return 0
|
|
100
91
|
})
|
|
@@ -49,7 +49,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
|
|
|
49
49
|
* if neccesary
|
|
50
50
|
*/
|
|
51
51
|
const linkLoader = {
|
|
52
|
-
test: /\.(jsx?|scss)$/,
|
|
52
|
+
test: /\.(jsx?|tsx?|scss)$/,
|
|
53
53
|
enforce: 'pre', // this will ensure is execute before transformations
|
|
54
54
|
use: {
|
|
55
55
|
loader: require.resolve('./LinkLoader'),
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "9.43.0-
|
|
3
|
+
"version": "9.43.0-typescript.0",
|
|
4
4
|
"description": "Config-free bundler for ES6 React apps.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sui-bundler": "./bin/sui-bundler.js"
|
|
7
7
|
},
|
|
8
8
|
"main": "./bin/sui-bundler.js",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"postinstall": "node ./scripts/postinstall.js",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [],
|
|
@@ -21,9 +22,12 @@
|
|
|
21
22
|
},
|
|
22
23
|
"homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@babel/core": "7.
|
|
25
|
+
"@babel/core": "7.21.8",
|
|
26
|
+
"@s-ui/compiler-config": "1",
|
|
25
27
|
"@s-ui/helpers": "1",
|
|
26
28
|
"@s-ui/sass-loader": "1",
|
|
29
|
+
"@swc/core": "1.3.14",
|
|
30
|
+
"@swc/helpers": "0.4.12",
|
|
27
31
|
"address": "1.2.0",
|
|
28
32
|
"autoprefixer": "10.4.8",
|
|
29
33
|
"babel-loader": "8.2.5",
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
"css-minimizer-webpack-plugin": "4.0.0",
|
|
35
39
|
"esbuild": "0.15.5",
|
|
36
40
|
"escape-string-regexp": "4.0.0",
|
|
37
|
-
"fast-glob": "3.2.
|
|
41
|
+
"fast-glob": "3.2.12",
|
|
38
42
|
"find-free-ports": "3.0.0",
|
|
39
43
|
"html-webpack-plugin": "5.5.0",
|
|
40
44
|
"https-browserify": "1.0.0",
|
|
@@ -46,12 +50,11 @@
|
|
|
46
50
|
"stream-http": "3.2.0",
|
|
47
51
|
"strip-ansi": "6.0.1",
|
|
48
52
|
"style-loader": "3.3.1",
|
|
53
|
+
"swc-loader": "0.2.1",
|
|
49
54
|
"url": "0.11.0",
|
|
50
55
|
"webpack": "5.82.1",
|
|
51
56
|
"webpack-dev-server": "4.10.0",
|
|
52
57
|
"webpack-manifest-plugin": "5.0.0",
|
|
53
|
-
"webpack-node-externals": "3.0.0"
|
|
54
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
|
55
|
-
"react-refresh": "0.14.0"
|
|
58
|
+
"webpack-node-externals": "3.0.0"
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
const crypto = require('crypto')
|
|
5
|
+
const fs = require('fs-extra')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const {writeFile} = require('@s-ui/helpers/file.js')
|
|
8
|
+
const {dynamicPackage} = require('@s-ui/helpers/packages')
|
|
9
|
+
|
|
10
|
+
const {INIT_CWD} = process.env
|
|
11
|
+
const tsConfigTemplate = `\
|
|
12
|
+
{
|
|
13
|
+
"extends": "@s-ui/bundler/tsconfig.json",
|
|
14
|
+
"compilerOptions": {
|
|
15
|
+
"rootDir": "./"
|
|
16
|
+
},
|
|
17
|
+
"include": ["src", "domain", "components"]
|
|
18
|
+
}`
|
|
19
|
+
|
|
20
|
+
const md5 = str => crypto.createHash('md5').update(str).digest('hex')
|
|
21
|
+
const TS_CONFIG_PATH = path.join(INIT_CWD, 'tsconfig.json')
|
|
22
|
+
const PACKAGE_JSON_CONFIG_PATH = path.join(INIT_CWD, 'package.json')
|
|
23
|
+
|
|
24
|
+
const config = require(PACKAGE_JSON_CONFIG_PATH)?.config?.['sui-bundler'] || {}
|
|
25
|
+
|
|
26
|
+
const shouldGenerateTSConfig = () => {
|
|
27
|
+
try {
|
|
28
|
+
if (!config?.type || config?.type !== 'typescript') return false
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync(TS_CONFIG_PATH)) return true
|
|
31
|
+
|
|
32
|
+
const tsConfigLocal = fs.readFileSync(TS_CONFIG_PATH, {encoding: 'utf8'})
|
|
33
|
+
return md5(tsConfigLocal) !== md5(tsConfigTemplate)
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function main() {
|
|
40
|
+
console.log(
|
|
41
|
+
'🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...'
|
|
42
|
+
)
|
|
43
|
+
if (!shouldGenerateTSConfig()) {
|
|
44
|
+
console.log('✅ [sui-bundler postinstall] tsconfig.json is up to date')
|
|
45
|
+
process.exit(0)
|
|
46
|
+
}
|
|
47
|
+
await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
|
|
48
|
+
await dynamicPackage('typescript')
|
|
49
|
+
console.log(
|
|
50
|
+
'❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it'
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
main()
|
package/shared/define.js
CHANGED
|
@@ -6,9 +6,24 @@ if (process.platform === 'win32') {
|
|
|
6
6
|
process.env.PWD = process.cwd()
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const {MAGIC_STRINGS = '{}'} = process.env
|
|
10
|
+
|
|
11
|
+
let magic
|
|
12
|
+
try {
|
|
13
|
+
magic = JSON.parse(MAGIC_STRINGS)
|
|
14
|
+
} catch (err) {
|
|
15
|
+
magic = {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = (vars = {}) => {
|
|
19
|
+
const definitions = {
|
|
11
20
|
__DEV__: false,
|
|
12
21
|
__BASE_DIR__: JSON.stringify(process.env.PWD),
|
|
13
|
-
...vars
|
|
14
|
-
|
|
22
|
+
...vars,
|
|
23
|
+
...Object.fromEntries(
|
|
24
|
+
Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)])
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new webpack.DefinePlugin(definitions)
|
|
29
|
+
}
|
package/shared/index.js
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const fs = require('fs-extra')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const {config} = require('./index.js')
|
|
5
|
+
const {getSWCConfig} = require('@s-ui/compiler-config')
|
|
6
|
+
|
|
7
|
+
const EXCLUDED_FOLDERS_REGEXP = new RegExp(
|
|
8
|
+
`node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const getTSConfig = () => {
|
|
12
|
+
// Get TS config from the package dir.
|
|
13
|
+
const tsConfigPath = path.join(process.cwd(), 'tsconfig.json')
|
|
14
|
+
let tsConfig
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
if (fs.existsSync(tsConfigPath)) {
|
|
18
|
+
tsConfig = JSON.parse(fs.readFileSync(tsConfigPath, {encoding: 'utf8'}))
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error(err)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return tsConfig
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = ({isServer = false, supportLegacyBrowsers = true} = {}) => {
|
|
28
|
+
const tsConfig = getTSConfig()
|
|
29
|
+
// If TS config exists in root dir, set TypeScript as enabled.
|
|
30
|
+
const isTypeScriptEnabled = Boolean(tsConfig)
|
|
31
|
+
|
|
32
|
+
return isTypeScriptEnabled
|
|
33
|
+
? {
|
|
34
|
+
test: /\.(js|ts)x?$/,
|
|
35
|
+
exclude: EXCLUDED_FOLDERS_REGEXP,
|
|
36
|
+
use: [
|
|
37
|
+
{
|
|
38
|
+
loader: require.resolve('swc-loader'),
|
|
39
|
+
options: getSWCConfig({isModern: false, isTypeScript: true})
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
: {
|
|
44
|
+
test: /\.jsx?$/,
|
|
45
|
+
exclude: EXCLUDED_FOLDERS_REGEXP,
|
|
46
|
+
use: [
|
|
47
|
+
{
|
|
48
|
+
loader: require.resolve('babel-loader'),
|
|
49
|
+
options: {
|
|
50
|
+
cacheDirectory: true,
|
|
51
|
+
cacheCompression: false,
|
|
52
|
+
babelrc: false,
|
|
53
|
+
compact: true,
|
|
54
|
+
presets: [
|
|
55
|
+
[
|
|
56
|
+
require.resolve('babel-preset-sui'),
|
|
57
|
+
{
|
|
58
|
+
isServer,
|
|
59
|
+
isModern: !supportLegacyBrowsers,
|
|
60
|
+
targets: config.targets
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
package/shared/resolve-alias.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const {config} = require('./config.js')
|
|
3
|
+
const fs = require('fs')
|
|
3
4
|
|
|
4
5
|
const {PWD} = process.env
|
|
5
6
|
|
|
@@ -11,22 +12,33 @@ const {PWD} = process.env
|
|
|
11
12
|
*/
|
|
12
13
|
const defaultPackagesToAlias = [
|
|
13
14
|
'react',
|
|
15
|
+
'react-dom',
|
|
14
16
|
'react-router-dom',
|
|
17
|
+
'react/jsx-dev-runtime',
|
|
18
|
+
'react/jsx-runtime',
|
|
15
19
|
'@s-ui/pde',
|
|
16
20
|
'@s-ui/react-context',
|
|
17
21
|
'@s-ui/react-router'
|
|
18
22
|
]
|
|
19
23
|
|
|
20
|
-
const createAliasPath = pkgName =>
|
|
21
|
-
path.
|
|
24
|
+
const createAliasPath = pkgName => {
|
|
25
|
+
const PWDNodeModules = path.join(PWD, './node_modules')
|
|
26
|
+
if (fs.existsSync(PWDNodeModules))
|
|
27
|
+
return path.resolve(path.join(PWDNodeModules, pkgName))
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
try {
|
|
30
|
+
return require.resolve(pkgName).replace(/\/index\.js$/, '')
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return ''
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
|
|
36
|
+
const mustPackagesToAlias = {}
|
|
37
|
+
|
|
28
38
|
exports.defaultAlias = Object.fromEntries(
|
|
29
|
-
defaultPackagesToAlias
|
|
39
|
+
defaultPackagesToAlias
|
|
40
|
+
.map(pkgName => [pkgName, createAliasPath(pkgName)])
|
|
41
|
+
.filter(([, path]) => path)
|
|
30
42
|
)
|
|
31
43
|
|
|
32
44
|
const aliasFromConfig = config.alias
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/* globals __webpack_hash__ */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict'
|
|
13
|
+
|
|
14
|
+
// This alternative WebpackDevServer combines the functionality of:
|
|
15
|
+
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
|
|
16
|
+
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
|
|
17
|
+
|
|
18
|
+
// It only supports their simplest configuration (hot updates on same server).
|
|
19
|
+
// It makes some opinionated choices on top, like adding a syntax error overlay
|
|
20
|
+
// that looks similar to our console output. The error overlay is inspired by:
|
|
21
|
+
// https://github.com/glenjamin/webpack-hot-middleware
|
|
22
|
+
|
|
23
|
+
const stripAnsi = require('strip-ansi')
|
|
24
|
+
const url = require('url')
|
|
25
|
+
const formatWebpackMessages = require('./formatWebpackMessages.js')
|
|
26
|
+
|
|
27
|
+
// We need to keep track of if there has been a runtime error.
|
|
28
|
+
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
29
|
+
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
30
|
+
// application. This is handled below when we are notified of a compile (code
|
|
31
|
+
// change).
|
|
32
|
+
// See https://github.com/facebook/create-react-app/issues/3096
|
|
33
|
+
const hadRuntimeError = false
|
|
34
|
+
|
|
35
|
+
// Connect to WebpackDevServer via a socket.
|
|
36
|
+
const connection = new WebSocket(
|
|
37
|
+
url.format({
|
|
38
|
+
protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
|
|
39
|
+
hostname: process.env.WDS_SOCKET_HOST || window.location.hostname,
|
|
40
|
+
port: process.env.WDS_SOCKET_PORT || window.location.port,
|
|
41
|
+
// Hardcoded in WebpackDevServer
|
|
42
|
+
pathname: process.env.WDS_SOCKET_PATH || '/ws',
|
|
43
|
+
slashes: true
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
// Unlike WebpackDevServer client, we won't try to reconnect
|
|
48
|
+
// to avoid spamming the console. Disconnect usually happens
|
|
49
|
+
// when developer stops the server.
|
|
50
|
+
connection.onclose = function () {
|
|
51
|
+
if (typeof console !== 'undefined' && typeof console.info === 'function') {
|
|
52
|
+
console.info(
|
|
53
|
+
'The development server has disconnected.\nRefresh the page if necessary.'
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Remember some state related to hot module replacement.
|
|
59
|
+
let isFirstCompilation = true
|
|
60
|
+
let mostRecentCompilationHash = null
|
|
61
|
+
let hasCompileErrors = false
|
|
62
|
+
|
|
63
|
+
function clearOutdatedErrors() {
|
|
64
|
+
// Clean up outdated compile errors, if any.
|
|
65
|
+
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
|
|
66
|
+
if (hasCompileErrors) {
|
|
67
|
+
console.clear()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Successful compilation.
|
|
73
|
+
function handleSuccess() {
|
|
74
|
+
clearOutdatedErrors()
|
|
75
|
+
|
|
76
|
+
const isHotUpdate = !isFirstCompilation
|
|
77
|
+
isFirstCompilation = false
|
|
78
|
+
hasCompileErrors = false
|
|
79
|
+
|
|
80
|
+
// Attempt to apply hot updates or reload.
|
|
81
|
+
if (isHotUpdate) {
|
|
82
|
+
tryApplyUpdates()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Compilation with warnings (e.g. ESLint).
|
|
87
|
+
function handleWarnings(warnings) {
|
|
88
|
+
clearOutdatedErrors()
|
|
89
|
+
|
|
90
|
+
const isHotUpdate = !isFirstCompilation
|
|
91
|
+
isFirstCompilation = false
|
|
92
|
+
hasCompileErrors = false
|
|
93
|
+
|
|
94
|
+
function printWarnings() {
|
|
95
|
+
// Print warnings to the console.
|
|
96
|
+
const formatted = formatWebpackMessages({
|
|
97
|
+
warnings,
|
|
98
|
+
errors: []
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
102
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
103
|
+
if (i === 5) {
|
|
104
|
+
console.warn(
|
|
105
|
+
'There were more warnings in other files.\n' +
|
|
106
|
+
'You can find a complete log in the terminal.'
|
|
107
|
+
)
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
console.warn(stripAnsi(formatted.warnings[i]))
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
printWarnings()
|
|
116
|
+
|
|
117
|
+
// Attempt to apply hot updates or reload.
|
|
118
|
+
if (isHotUpdate) {
|
|
119
|
+
tryApplyUpdates()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Compilation with errors (e.g. syntax error or missing modules).
|
|
124
|
+
function handleErrors(errors) {
|
|
125
|
+
clearOutdatedErrors()
|
|
126
|
+
|
|
127
|
+
isFirstCompilation = false
|
|
128
|
+
hasCompileErrors = true
|
|
129
|
+
|
|
130
|
+
// "Massage" webpack messages.
|
|
131
|
+
const formatted = formatWebpackMessages({
|
|
132
|
+
errors,
|
|
133
|
+
warnings: []
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// Also log them to the console.
|
|
137
|
+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
138
|
+
for (let i = 0; i < formatted.errors.length; i++) {
|
|
139
|
+
console.error(stripAnsi(formatted.errors[i]))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Do not attempt to reload now.
|
|
144
|
+
// We will reload on next success instead.
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// There is a newer version of the code available.
|
|
148
|
+
function handleAvailableHash(hash) {
|
|
149
|
+
// Update last known compilation hash.
|
|
150
|
+
mostRecentCompilationHash = hash
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Handle messages from the server.
|
|
154
|
+
connection.onmessage = function (e) {
|
|
155
|
+
const message = JSON.parse(e.data)
|
|
156
|
+
switch (message.type) {
|
|
157
|
+
case 'hash':
|
|
158
|
+
handleAvailableHash(message.data)
|
|
159
|
+
break
|
|
160
|
+
case 'still-ok':
|
|
161
|
+
case 'ok':
|
|
162
|
+
handleSuccess()
|
|
163
|
+
break
|
|
164
|
+
case 'content-changed':
|
|
165
|
+
// Triggered when a file from `contentBase` changed.
|
|
166
|
+
window.location.reload()
|
|
167
|
+
break
|
|
168
|
+
case 'warnings':
|
|
169
|
+
handleWarnings(message.data)
|
|
170
|
+
break
|
|
171
|
+
case 'errors':
|
|
172
|
+
handleErrors(message.data)
|
|
173
|
+
break
|
|
174
|
+
default:
|
|
175
|
+
// Do nothing.
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Is there a newer version of this code available?
|
|
180
|
+
function isUpdateAvailable() {
|
|
181
|
+
// __webpack_hash__ is the hash of the current compilation.
|
|
182
|
+
// It's a global variable injected by webpack.
|
|
183
|
+
// eslint-disable-next-line camelcase
|
|
184
|
+
return mostRecentCompilationHash !== __webpack_hash__
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// webpack disallows updates in other states.
|
|
188
|
+
function canApplyUpdates() {
|
|
189
|
+
return module.hot.status() === 'idle'
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function canAcceptErrors() {
|
|
193
|
+
// NOTE: This var is injected by Webpack's DefinePlugin, and is a boolean instead of string.
|
|
194
|
+
const hasReactRefresh = process.env.FAST_REFRESH
|
|
195
|
+
|
|
196
|
+
const status = module.hot.status()
|
|
197
|
+
// React refresh can handle hot-reloading over errors.
|
|
198
|
+
// However, when hot-reload status is abort or fail,
|
|
199
|
+
// it indicates the current update cannot be applied safely,
|
|
200
|
+
// and thus we should bail out to a forced reload for consistency.
|
|
201
|
+
return hasReactRefresh && ['abort', 'fail'].indexOf(status) === -1
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Attempt to update code on the fly, fall back to a hard reload.
|
|
205
|
+
function tryApplyUpdates(onHotUpdateSuccess) {
|
|
206
|
+
if (!module.hot) {
|
|
207
|
+
// HotModuleReplacementPlugin is not in webpack configuration.
|
|
208
|
+
window.location.reload()
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
217
|
+
const haveErrors = err || hadRuntimeError
|
|
218
|
+
// When there is no error but updatedModules is unavailable,
|
|
219
|
+
// it indicates a critical failure in hot-reloading,
|
|
220
|
+
// e.g. server is not ready to serve new bundle,
|
|
221
|
+
// and hence we need to do a forced reload.
|
|
222
|
+
const needsForcedReload = !err && !updatedModules
|
|
223
|
+
if ((haveErrors && !canAcceptErrors()) || needsForcedReload) {
|
|
224
|
+
window.location.reload()
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (typeof onHotUpdateSuccess === 'function') {
|
|
229
|
+
// Maybe we want to do something.
|
|
230
|
+
onHotUpdateSuccess()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (isUpdateAvailable()) {
|
|
234
|
+
// While we were updating, there was a new update! Do it again.
|
|
235
|
+
tryApplyUpdates()
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// https://webpack.github.io/docs/hot-module-replacement.html#check
|
|
240
|
+
const result = module.hot.check(/* autoApply */ true, handleApplyUpdates)
|
|
241
|
+
|
|
242
|
+
// // webpack 2 returns a Promise instead of invoking a callback
|
|
243
|
+
if (result && result.then) {
|
|
244
|
+
result.then(
|
|
245
|
+
function (updatedModules) {
|
|
246
|
+
handleApplyUpdates(null, updatedModules)
|
|
247
|
+
},
|
|
248
|
+
function (err) {
|
|
249
|
+
handleApplyUpdates(err, null)
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
}
|
package/webpack.config.dev.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const webpack = require('webpack')
|
|
5
5
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
6
|
-
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
|
|
7
6
|
|
|
8
7
|
const {
|
|
9
8
|
envVars,
|
|
@@ -18,7 +17,7 @@ const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
|
18
17
|
const {supportLegacyBrowsers} = require('./shared/config.js')
|
|
19
18
|
|
|
20
19
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
21
|
-
const
|
|
20
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
22
21
|
|
|
23
22
|
const outputPath = path.join(process.cwd(), 'dist')
|
|
24
23
|
|
|
@@ -28,6 +27,7 @@ process.env.NODE_ENV = 'development'
|
|
|
28
27
|
|
|
29
28
|
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
30
29
|
|
|
30
|
+
/** @type {WebpackConfig} */
|
|
31
31
|
const webpackConfig = {
|
|
32
32
|
mode: 'development',
|
|
33
33
|
context: path.resolve(PWD, 'src'),
|
|
@@ -47,16 +47,13 @@ const webpackConfig = {
|
|
|
47
47
|
timers: false
|
|
48
48
|
},
|
|
49
49
|
modules: ['node_modules', path.resolve(process.cwd())],
|
|
50
|
-
extensions: ['.js', '.json']
|
|
50
|
+
extensions: ['.js', '.tsx', '.ts', '.json']
|
|
51
51
|
},
|
|
52
52
|
stats: 'errors-only',
|
|
53
|
-
entry:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
static: outputPath,
|
|
58
|
-
hot: true
|
|
59
|
-
},
|
|
53
|
+
entry: cleanList([
|
|
54
|
+
require.resolve('./utils/webpackHotDevClient.js'),
|
|
55
|
+
MAIN_ENTRY_POINT
|
|
56
|
+
]),
|
|
60
57
|
target: 'web',
|
|
61
58
|
optimization: {
|
|
62
59
|
checkWasmTypes: false,
|
|
@@ -81,13 +78,12 @@ const webpackConfig = {
|
|
|
81
78
|
template: './index.html',
|
|
82
79
|
inject: true,
|
|
83
80
|
env: process.env
|
|
84
|
-
})
|
|
85
|
-
new ReactRefreshWebpackPlugin({overlay: false})
|
|
81
|
+
})
|
|
86
82
|
],
|
|
87
83
|
resolveLoader,
|
|
88
84
|
module: {
|
|
89
85
|
rules: cleanList([
|
|
90
|
-
|
|
86
|
+
createCompilerRules({supportLegacyBrowsers}),
|
|
91
87
|
{
|
|
92
88
|
test: /(\.css|\.scss)$/,
|
|
93
89
|
use: cleanList([
|
package/webpack.config.lib.js
CHANGED
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
const path = require('path')
|
|
10
10
|
const minifyJs = require('./shared/minify-js.js')
|
|
11
11
|
const definePlugin = require('./shared/define.js')
|
|
12
|
-
const
|
|
12
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
13
13
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
14
14
|
const {
|
|
15
15
|
extractComments,
|
|
@@ -67,6 +67,6 @@ module.exports = {
|
|
|
67
67
|
definePlugin()
|
|
68
68
|
]),
|
|
69
69
|
module: {
|
|
70
|
-
rules: [
|
|
70
|
+
rules: [createCompilerRules({supportLegacyBrowsers}), sassRules]
|
|
71
71
|
}
|
|
72
72
|
}
|
package/webpack.config.prod.js
CHANGED
|
@@ -23,7 +23,7 @@ const {
|
|
|
23
23
|
supportLegacyBrowsers
|
|
24
24
|
} = require('./shared/config.js')
|
|
25
25
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
26
|
-
const
|
|
26
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
27
27
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
28
28
|
const definePlugin = require('./shared/define.js')
|
|
29
29
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
@@ -54,7 +54,7 @@ const webpackConfig = {
|
|
|
54
54
|
context: path.resolve(CWD, 'src'),
|
|
55
55
|
resolve: {
|
|
56
56
|
alias: {...aliasFromConfig},
|
|
57
|
-
extensions: ['.js', '.json'],
|
|
57
|
+
extensions: ['.js', '.json', '.ts', '.tsx'],
|
|
58
58
|
modules: ['node_modules', path.resolve(CWD)],
|
|
59
59
|
fallback: {
|
|
60
60
|
assert: false,
|
|
@@ -114,7 +114,7 @@ const webpackConfig = {
|
|
|
114
114
|
]),
|
|
115
115
|
module: {
|
|
116
116
|
rules: cleanList([
|
|
117
|
-
|
|
117
|
+
createCompilerRules({supportLegacyBrowsers}),
|
|
118
118
|
sassRules,
|
|
119
119
|
when(config['externals-manifest'], () =>
|
|
120
120
|
manifestLoaderRules(config['externals-manifest'])
|
package/webpack.config.server.js
CHANGED
|
@@ -3,7 +3,7 @@ const webpackNodeExternals = require('webpack-node-externals')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
5
5
|
const {config, when, cleanList} = require('./shared/index.js')
|
|
6
|
-
const
|
|
6
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
7
7
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
8
8
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
9
9
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
@@ -18,7 +18,7 @@ const webpackConfig = {
|
|
|
18
18
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
19
19
|
resolve: {
|
|
20
20
|
alias: {...aliasFromConfig},
|
|
21
|
-
extensions: ['.js', '.json'],
|
|
21
|
+
extensions: ['.js', '.json', '.ts', '.tsx'],
|
|
22
22
|
modules: ['node_modules', path.resolve(process.cwd())]
|
|
23
23
|
},
|
|
24
24
|
entry: './server.js',
|
|
@@ -39,7 +39,7 @@ const webpackConfig = {
|
|
|
39
39
|
resolveLoader,
|
|
40
40
|
module: {
|
|
41
41
|
rules: cleanList([
|
|
42
|
-
|
|
42
|
+
createCompilerRules({isServer: true}),
|
|
43
43
|
{
|
|
44
44
|
// ignore css/scss/svg require/imports files in the server
|
|
45
45
|
test: /(\.svg|\.s?css)$/,
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const {config} = require('./index.js')
|
|
3
|
-
|
|
4
|
-
const EXCLUDED_FOLDERS_REGEXP = new RegExp(
|
|
5
|
-
`node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
module.exports = ({
|
|
9
|
-
isServer = false,
|
|
10
|
-
isDevelopment = false,
|
|
11
|
-
supportLegacyBrowsers = true
|
|
12
|
-
} = {}) => ({
|
|
13
|
-
test: /\.jsx?$/,
|
|
14
|
-
exclude: EXCLUDED_FOLDERS_REGEXP,
|
|
15
|
-
use: [
|
|
16
|
-
{
|
|
17
|
-
loader: require.resolve('babel-loader'),
|
|
18
|
-
options: {
|
|
19
|
-
cacheDirectory: true,
|
|
20
|
-
cacheCompression: false,
|
|
21
|
-
babelrc: false,
|
|
22
|
-
compact: true,
|
|
23
|
-
plugins: [
|
|
24
|
-
isDevelopment && require.resolve('react-refresh/babel')
|
|
25
|
-
].filter(Boolean),
|
|
26
|
-
presets: [
|
|
27
|
-
[
|
|
28
|
-
require.resolve('babel-preset-sui'),
|
|
29
|
-
{
|
|
30
|
-
isServer,
|
|
31
|
-
isModern: !supportLegacyBrowsers,
|
|
32
|
-
targets: config.targets
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
})
|