@s-ui/bundler 9.46.0-typescript.0 → 9.47.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-dev.js +1 -1
- package/factories/createDevServerConfig.js +10 -4
- package/loaders/linkLoaderConfigBuilder.js +1 -1
- package/package.json +3 -8
- package/shared/config.js +2 -0
- package/shared/define.js +4 -18
- package/shared/index.js +1 -1
- package/shared/module-rules-babel.js +33 -0
- package/shared/resolve-alias.js +6 -24
- package/{webpack.config.server.dev.js → webpack.config.client.dev.js} +7 -1
- package/webpack.config.dev.js +10 -4
- package/webpack.config.lib.js +3 -3
- package/webpack.config.prod.js +11 -5
- package/webpack.config.server.js +13 -4
- package/scripts/postinstall.js +0 -48
- package/shared/module-rules-compiler.js +0 -69
- package/tsconfig.json +0 -3
package/bin/sui-bundler-dev.js
CHANGED
|
@@ -57,7 +57,7 @@ if (!module.parent) {
|
|
|
57
57
|
const start = async ({config = webpackConfig, packagesToLink = program.opts().linkPackage || []} = {}) => {
|
|
58
58
|
clearConsole()
|
|
59
59
|
// Warn and crash if required files are missing
|
|
60
|
-
if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
|
|
60
|
+
if (!checkRequiredFiles([path.join(config.context, 'index.html'), path.join(config.context, 'app.js')])) {
|
|
61
61
|
log.error(`✖ Required files are missing, create and index.html and app.js inside your src folder.`)
|
|
62
62
|
process.exit(1)
|
|
63
63
|
}
|
|
@@ -30,10 +30,16 @@ module.exports = config => ({
|
|
|
30
30
|
'Access-Control-Allow-Methods': '*',
|
|
31
31
|
'Access-Control-Allow-Headers': '*'
|
|
32
32
|
},
|
|
33
|
-
static:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
static: [
|
|
34
|
+
{
|
|
35
|
+
directory: 'statics',
|
|
36
|
+
watch: getWatchOptions(config)
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
directory: 'public',
|
|
40
|
+
watch: getWatchOptions(config)
|
|
41
|
+
}
|
|
42
|
+
],
|
|
37
43
|
hot: true,
|
|
38
44
|
host,
|
|
39
45
|
historyApiFallback: {
|
|
@@ -43,7 +43,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
|
|
|
43
43
|
* if neccesary
|
|
44
44
|
*/
|
|
45
45
|
const linkLoader = {
|
|
46
|
-
test: /\.(jsx?|
|
|
46
|
+
test: /\.(jsx?|scss)$/,
|
|
47
47
|
enforce: 'pre', // this will ensure is execute before transformations
|
|
48
48
|
use: {
|
|
49
49
|
loader: require.resolve('./LinkLoader'),
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.47.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",
|
|
11
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
11
|
},
|
|
13
12
|
"keywords": [],
|
|
@@ -22,12 +21,9 @@
|
|
|
22
21
|
},
|
|
23
22
|
"homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme",
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@babel/core": "7.
|
|
26
|
-
"@s-ui/compiler-config": "1",
|
|
24
|
+
"@babel/core": "7.18.10",
|
|
27
25
|
"@s-ui/helpers": "1",
|
|
28
26
|
"@s-ui/sass-loader": "1",
|
|
29
|
-
"@swc/core": "1.3.14",
|
|
30
|
-
"@swc/helpers": "0.4.12",
|
|
31
27
|
"address": "1.2.2",
|
|
32
28
|
"autoprefixer": "10.4.8",
|
|
33
29
|
"babel-loader": "8.2.5",
|
|
@@ -38,7 +34,7 @@
|
|
|
38
34
|
"css-minimizer-webpack-plugin": "4.0.0",
|
|
39
35
|
"esbuild": "0.15.5",
|
|
40
36
|
"escape-string-regexp": "4.0.0",
|
|
41
|
-
"fast-glob": "3.2.
|
|
37
|
+
"fast-glob": "3.2.11",
|
|
42
38
|
"find-free-ports": "3.0.0",
|
|
43
39
|
"html-webpack-plugin": "5.5.0",
|
|
44
40
|
"https-browserify": "1.0.0",
|
|
@@ -50,7 +46,6 @@
|
|
|
50
46
|
"stream-http": "3.2.0",
|
|
51
47
|
"strip-ansi": "6.0.1",
|
|
52
48
|
"style-loader": "3.3.1",
|
|
53
|
-
"swc-loader": "0.2.1",
|
|
54
49
|
"url": "0.11.0",
|
|
55
50
|
"webpack": "5.82.1",
|
|
56
51
|
"webpack-dev-server": "4.10.0",
|
package/shared/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* Extract sui-bundler from package.json -> "config": {"sui-bundler": { ... }} */
|
|
2
|
+
const path = require('path')
|
|
2
3
|
const {config: packageJsonConfig = {}} = require(`${process.cwd()}/package.json`)
|
|
3
4
|
|
|
4
5
|
const {'sui-bundler': config = {}} = packageJsonConfig
|
|
@@ -8,3 +9,4 @@ exports.config = config
|
|
|
8
9
|
exports.supportLegacyBrowsers = supportLegacyBrowsers
|
|
9
10
|
exports.extractComments = extractComments
|
|
10
11
|
exports.sourceMap = (sourcemaps && sourcemaps.prod) || false
|
|
12
|
+
exports.cacheDirectory = path.resolve(process.cwd(), '.sui/cache')
|
package/shared/define.js
CHANGED
|
@@ -6,23 +6,9 @@ if (process.platform === 'win32') {
|
|
|
6
6
|
process.env.PWD = process.cwd()
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
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 = {
|
|
9
|
+
module.exports = (vars = {}) =>
|
|
10
|
+
new webpack.DefinePlugin({
|
|
20
11
|
__DEV__: false,
|
|
21
12
|
__BASE_DIR__: JSON.stringify(process.env.PWD),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
...Object.fromEntries(Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)]))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return new webpack.DefinePlugin(definitions)
|
|
28
|
-
}
|
|
13
|
+
...vars
|
|
14
|
+
})
|
package/shared/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
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 = ({isServer = false, isDevelopment = false, supportLegacyBrowsers = true} = {}) => ({
|
|
9
|
+
test: /\.jsx?$/,
|
|
10
|
+
exclude: EXCLUDED_FOLDERS_REGEXP,
|
|
11
|
+
use: [
|
|
12
|
+
{
|
|
13
|
+
loader: require.resolve('babel-loader'),
|
|
14
|
+
options: {
|
|
15
|
+
cacheDirectory: true,
|
|
16
|
+
cacheCompression: false,
|
|
17
|
+
babelrc: false,
|
|
18
|
+
compact: true,
|
|
19
|
+
plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
|
|
20
|
+
presets: [
|
|
21
|
+
[
|
|
22
|
+
require.resolve('babel-preset-sui'),
|
|
23
|
+
{
|
|
24
|
+
isServer,
|
|
25
|
+
isModern: !supportLegacyBrowsers,
|
|
26
|
+
targets: config.targets
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
})
|
package/shared/resolve-alias.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const {config} = require('./config.js')
|
|
3
|
-
const fs = require('fs')
|
|
4
3
|
|
|
5
4
|
const {PWD} = process.env
|
|
6
5
|
|
|
@@ -10,33 +9,16 @@ const {PWD} = process.env
|
|
|
10
9
|
* So you should use the exact same imported file from node_modules, and the linked package
|
|
11
10
|
* would try to use another different from its own node_modules. This will prevent that.
|
|
12
11
|
*/
|
|
13
|
-
const defaultPackagesToAlias = [
|
|
14
|
-
'react',
|
|
15
|
-
'react-dom',
|
|
16
|
-
'react-router-dom',
|
|
17
|
-
'react/jsx-dev-runtime',
|
|
18
|
-
'react/jsx-runtime',
|
|
19
|
-
'@s-ui/pde',
|
|
20
|
-
'@s-ui/react-context',
|
|
21
|
-
'@s-ui/react-router'
|
|
22
|
-
]
|
|
12
|
+
const defaultPackagesToAlias = ['react', 'react-router-dom', '@s-ui/pde', '@s-ui/react-context', '@s-ui/react-router']
|
|
23
13
|
|
|
24
|
-
const createAliasPath = pkgName => {
|
|
25
|
-
const PWDNodeModules = path.join(PWD, './node_modules')
|
|
26
|
-
if (fs.existsSync(PWDNodeModules)) return path.resolve(path.join(PWDNodeModules, pkgName))
|
|
14
|
+
const createAliasPath = pkgName => path.resolve(path.join(PWD, `./node_modules/${pkgName}`))
|
|
27
15
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return ''
|
|
32
|
-
}
|
|
16
|
+
const mustPackagesToAlias = {
|
|
17
|
+
'react/jsx-dev-runtime': 'react/jsx-dev-runtime.js',
|
|
18
|
+
'react/jsx-runtime': 'react/jsx-runtime.js'
|
|
33
19
|
}
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
exports.defaultAlias = Object.fromEntries(
|
|
38
|
-
defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)]).filter(([, path]) => path)
|
|
39
|
-
)
|
|
21
|
+
exports.defaultAlias = Object.fromEntries(defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)]))
|
|
40
22
|
|
|
41
23
|
const aliasFromConfig = config.alias
|
|
42
24
|
? Object.entries(config.alias).reduce(
|
|
@@ -11,7 +11,7 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/i
|
|
|
11
11
|
const definePlugin = require('./shared/define.js')
|
|
12
12
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
13
13
|
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
14
|
-
const {supportLegacyBrowsers} = require('./shared/config.js')
|
|
14
|
+
const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
|
|
15
15
|
|
|
16
16
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
17
17
|
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
@@ -25,6 +25,7 @@ process.env.NODE_ENV = 'development'
|
|
|
25
25
|
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
26
26
|
|
|
27
27
|
const webpackConfig = {
|
|
28
|
+
name: 'client',
|
|
28
29
|
mode: 'development',
|
|
29
30
|
context: path.resolve(PWD, 'src'),
|
|
30
31
|
resolve: {
|
|
@@ -49,6 +50,11 @@ const webpackConfig = {
|
|
|
49
50
|
entry: {
|
|
50
51
|
app: [`webpack-hot-middleware/client?path=${CDN}__webpack_hmr`, MAIN_ENTRY_POINT]
|
|
51
52
|
},
|
|
53
|
+
cache: {
|
|
54
|
+
type: 'filesystem',
|
|
55
|
+
cacheDirectory,
|
|
56
|
+
compression: 'brotli'
|
|
57
|
+
},
|
|
52
58
|
target: 'web',
|
|
53
59
|
optimization: {
|
|
54
60
|
checkWasmTypes: false,
|
package/webpack.config.dev.js
CHANGED
|
@@ -9,10 +9,10 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/i
|
|
|
9
9
|
const definePlugin = require('./shared/define.js')
|
|
10
10
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
11
11
|
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
12
|
-
const {supportLegacyBrowsers} = require('./shared/config.js')
|
|
12
|
+
const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
|
|
13
13
|
|
|
14
14
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
15
|
-
const
|
|
15
|
+
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
16
16
|
|
|
17
17
|
const outputPath = path.join(process.cwd(), 'dist')
|
|
18
18
|
|
|
@@ -23,6 +23,7 @@ process.env.NODE_ENV = 'development'
|
|
|
23
23
|
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
24
24
|
|
|
25
25
|
const webpackConfig = {
|
|
26
|
+
name: 'client-local',
|
|
26
27
|
mode: 'development',
|
|
27
28
|
context: path.resolve(PWD, 'src'),
|
|
28
29
|
resolve: {
|
|
@@ -41,7 +42,7 @@ const webpackConfig = {
|
|
|
41
42
|
timers: false
|
|
42
43
|
},
|
|
43
44
|
modules: ['node_modules', path.resolve(process.cwd())],
|
|
44
|
-
extensions: ['.js', '.
|
|
45
|
+
extensions: ['.js', '.json']
|
|
45
46
|
},
|
|
46
47
|
stats: 'errors-only',
|
|
47
48
|
entry: {
|
|
@@ -51,6 +52,11 @@ const webpackConfig = {
|
|
|
51
52
|
static: outputPath,
|
|
52
53
|
hot: true
|
|
53
54
|
},
|
|
55
|
+
cache: {
|
|
56
|
+
type: 'filesystem',
|
|
57
|
+
cacheDirectory,
|
|
58
|
+
compression: 'brotli'
|
|
59
|
+
},
|
|
54
60
|
target: 'web',
|
|
55
61
|
optimization: {
|
|
56
62
|
checkWasmTypes: false,
|
|
@@ -81,7 +87,7 @@ const webpackConfig = {
|
|
|
81
87
|
resolveLoader,
|
|
82
88
|
module: {
|
|
83
89
|
rules: cleanList([
|
|
84
|
-
|
|
90
|
+
createBabelRules({supportLegacyBrowsers, isDevelopment: true}),
|
|
85
91
|
{
|
|
86
92
|
test: /(\.css|\.scss)$/,
|
|
87
93
|
use: cleanList([
|
package/webpack.config.lib.js
CHANGED
|
@@ -4,7 +4,7 @@ const {cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.j
|
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const minifyJs = require('./shared/minify-js.js')
|
|
6
6
|
const definePlugin = require('./shared/define.js')
|
|
7
|
-
const
|
|
7
|
+
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
8
8
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
9
9
|
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
|
|
10
10
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
@@ -45,7 +45,7 @@ module.exports = {
|
|
|
45
45
|
},
|
|
46
46
|
plugins: cleanList([
|
|
47
47
|
new webpack.ProvidePlugin({
|
|
48
|
-
process: 'process/browser
|
|
48
|
+
process: 'process/browser'
|
|
49
49
|
}),
|
|
50
50
|
new MiniCssExtractPlugin({
|
|
51
51
|
filename: cssFileName,
|
|
@@ -58,6 +58,6 @@ module.exports = {
|
|
|
58
58
|
definePlugin()
|
|
59
59
|
]),
|
|
60
60
|
module: {
|
|
61
|
-
rules: [
|
|
61
|
+
rules: [createBabelRules({supportLegacyBrowsers}), sassRules]
|
|
62
62
|
}
|
|
63
63
|
}
|
package/webpack.config.prod.js
CHANGED
|
@@ -11,9 +11,9 @@ const InlineChunkHtmlPlugin = require('./shared/inline-chunk-html-plugin.js')
|
|
|
11
11
|
|
|
12
12
|
const {when, cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.js')
|
|
13
13
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
14
|
-
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
|
|
14
|
+
const {extractComments, sourceMap, supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
|
|
15
15
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
16
|
-
const
|
|
16
|
+
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
17
17
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
18
18
|
const definePlugin = require('./shared/define.js')
|
|
19
19
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
@@ -35,12 +35,13 @@ const target = supportLegacyBrowsers ? ['web', 'es5'] : 'web'
|
|
|
35
35
|
/** @type {WebpackConfig} */
|
|
36
36
|
const webpackConfig = {
|
|
37
37
|
devtool: sourceMap,
|
|
38
|
+
name: 'client',
|
|
38
39
|
mode: 'production',
|
|
39
40
|
target,
|
|
40
41
|
context: path.resolve(CWD, 'src'),
|
|
41
42
|
resolve: {
|
|
42
43
|
alias: {...aliasFromConfig},
|
|
43
|
-
extensions: ['.js', '.json'
|
|
44
|
+
extensions: ['.js', '.json'],
|
|
44
45
|
modules: ['node_modules', path.resolve(CWD)],
|
|
45
46
|
fallback: {
|
|
46
47
|
assert: false,
|
|
@@ -66,9 +67,14 @@ const webpackConfig = {
|
|
|
66
67
|
minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(Boolean),
|
|
67
68
|
runtimeChunk: true
|
|
68
69
|
},
|
|
70
|
+
cache: {
|
|
71
|
+
type: 'filesystem',
|
|
72
|
+
cacheDirectory,
|
|
73
|
+
compression: false
|
|
74
|
+
},
|
|
69
75
|
plugins: cleanList([
|
|
70
76
|
new webpack.ProvidePlugin({
|
|
71
|
-
process: 'process/browser
|
|
77
|
+
process: 'process/browser'
|
|
72
78
|
}),
|
|
73
79
|
new webpack.ids.HashedModuleIdsPlugin(),
|
|
74
80
|
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
@@ -98,7 +104,7 @@ const webpackConfig = {
|
|
|
98
104
|
]),
|
|
99
105
|
module: {
|
|
100
106
|
rules: cleanList([
|
|
101
|
-
|
|
107
|
+
createBabelRules({supportLegacyBrowsers}),
|
|
102
108
|
sassRules,
|
|
103
109
|
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
|
|
104
110
|
])
|
package/webpack.config.server.js
CHANGED
|
@@ -3,7 +3,8 @@ 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 {cacheDirectory} = require('./shared/config.js')
|
|
7
|
+
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
7
8
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
8
9
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
9
10
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
@@ -12,13 +13,16 @@ const filename = '[name].[chunkhash:8].js'
|
|
|
12
13
|
|
|
13
14
|
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
14
15
|
|
|
16
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
17
|
+
|
|
15
18
|
/** @type {WebpackConfig} */
|
|
16
19
|
const webpackConfig = {
|
|
20
|
+
name: 'server',
|
|
17
21
|
context: path.resolve(process.cwd(), 'src'),
|
|
18
|
-
mode:
|
|
22
|
+
mode: isProduction ? 'production' : 'development',
|
|
19
23
|
resolve: {
|
|
20
24
|
alias: {...aliasFromConfig},
|
|
21
|
-
extensions: ['.js', '.json'
|
|
25
|
+
extensions: ['.js', '.json'],
|
|
22
26
|
modules: ['node_modules', path.resolve(process.cwd())]
|
|
23
27
|
},
|
|
24
28
|
entry: './server.js',
|
|
@@ -34,12 +38,17 @@ const webpackConfig = {
|
|
|
34
38
|
minimize: true,
|
|
35
39
|
nodeEnv: false
|
|
36
40
|
},
|
|
41
|
+
cache: {
|
|
42
|
+
type: 'filesystem',
|
|
43
|
+
cacheDirectory,
|
|
44
|
+
compression: !isProduction ? 'brotli' : false
|
|
45
|
+
},
|
|
37
46
|
externals: [webpackNodeExternals()],
|
|
38
47
|
plugins: [new webpack.DefinePlugin({'global.GENTLY': false})],
|
|
39
48
|
resolveLoader,
|
|
40
49
|
module: {
|
|
41
50
|
rules: cleanList([
|
|
42
|
-
|
|
51
|
+
createBabelRules({isServer: true}),
|
|
43
52
|
{
|
|
44
53
|
// ignore css/scss/svg require/imports files in the server
|
|
45
54
|
test: /(\.svg|\.s?css)$/,
|
package/scripts/postinstall.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
const {INIT_CWD} = process.env
|
|
10
|
-
const tsConfigTemplate = `\
|
|
11
|
-
{
|
|
12
|
-
"extends": "@s-ui/bundler/tsconfig.json",
|
|
13
|
-
"compilerOptions": {
|
|
14
|
-
"rootDir": "./"
|
|
15
|
-
},
|
|
16
|
-
"include": ["src", "domain", "components"]
|
|
17
|
-
}`
|
|
18
|
-
|
|
19
|
-
const md5 = str => crypto.createHash('md5').update(str).digest('hex')
|
|
20
|
-
const TS_CONFIG_PATH = path.join(INIT_CWD, 'tsconfig.json')
|
|
21
|
-
const PACKAGE_JSON_CONFIG_PATH = path.join(INIT_CWD, 'package.json')
|
|
22
|
-
|
|
23
|
-
const config = require(PACKAGE_JSON_CONFIG_PATH)?.config?.['sui-bundler'] || {}
|
|
24
|
-
|
|
25
|
-
const shouldGenerateTSConfig = () => {
|
|
26
|
-
try {
|
|
27
|
-
if (!config?.type || config?.type !== 'typescript') return false
|
|
28
|
-
|
|
29
|
-
if (!fs.existsSync(TS_CONFIG_PATH)) return true
|
|
30
|
-
|
|
31
|
-
const tsConfigLocal = fs.readFileSync(TS_CONFIG_PATH, {encoding: 'utf8'})
|
|
32
|
-
return md5(tsConfigLocal) !== md5(tsConfigTemplate)
|
|
33
|
-
} catch (err) {
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function main() {
|
|
39
|
-
console.log('🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...')
|
|
40
|
-
if (!shouldGenerateTSConfig()) {
|
|
41
|
-
console.log('✅ [sui-bundler postinstall] tsconfig.json is up to date')
|
|
42
|
-
process.exit(0)
|
|
43
|
-
}
|
|
44
|
-
await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
|
|
45
|
-
console.log('❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
main()
|
|
@@ -1,69 +0,0 @@
|
|
|
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, isDevelopment = 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
|
-
plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
|
|
55
|
-
presets: [
|
|
56
|
-
[
|
|
57
|
-
require.resolve('babel-preset-sui'),
|
|
58
|
-
{
|
|
59
|
-
isServer,
|
|
60
|
-
isModern: !supportLegacyBrowsers,
|
|
61
|
-
targets: config.targets
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
}
|
package/tsconfig.json
DELETED