@s-ui/bundler 9.43.0 → 9.45.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 +8 -30
- package/bin/sui-bundler-dev.js +5 -22
- package/bin/sui-bundler-lib.js +3 -13
- package/bin/sui-bundler.js +1 -4
- package/factories/createCompiler.js +2 -6
- package/loaders/ExternalsManifestLoader.js +1 -3
- package/loaders/linkLoaderConfigBuilder.js +3 -9
- package/loaders/sassLinkImporter.js +1 -4
- package/package.json +9 -4
- package/scripts/postinstall.js +48 -0
- package/service-worker.js +1 -3
- package/shared/config.js +2 -8
- package/shared/define.js +18 -4
- package/shared/index.js +1 -1
- package/shared/inline-chunk-html-plugin.js +2 -5
- package/shared/minify-js.js +1 -3
- package/shared/module-rules-compiler.js +69 -0
- package/shared/resolve-alias.js +16 -9
- package/shared/resolve-loader.js +1 -3
- package/tsconfig.json +3 -0
- package/utils/WebpackDevServerUtils.js +10 -42
- package/utils/clearConsole.js +1 -3
- package/utils/formatWebpackMessages.js +6 -20
- package/utils/getProcessForPort.js +4 -19
- package/utils/ignoredFiles.js +1 -6
- package/webpack.config.dev.js +6 -15
- package/webpack.config.lib.js +5 -14
- package/webpack.config.prod.js +10 -28
- package/webpack.config.server.dev.js +119 -0
- package/webpack.config.server.js +4 -6
- package/shared/module-rules-babel.js +0 -39
package/bin/sui-bundler-build.js
CHANGED
|
@@ -41,12 +41,7 @@ program
|
|
|
41
41
|
})
|
|
42
42
|
.parse(process.argv)
|
|
43
43
|
|
|
44
|
-
const {
|
|
45
|
-
clean = false,
|
|
46
|
-
context,
|
|
47
|
-
saveStats,
|
|
48
|
-
linkPackage: packagesToLink = []
|
|
49
|
-
} = program.opts()
|
|
44
|
+
const {clean = false, context, saveStats, linkPackage: packagesToLink = []} = program.opts()
|
|
50
45
|
|
|
51
46
|
config.context = context || config.context
|
|
52
47
|
|
|
@@ -106,10 +101,7 @@ compiler.run(async (error, stats) => {
|
|
|
106
101
|
const resolvePublicFile = file => path.resolve(process.cwd(), 'public', file)
|
|
107
102
|
|
|
108
103
|
if (offlinePageExists) {
|
|
109
|
-
fs.copyFileSync(
|
|
110
|
-
path.resolve(offlinePath),
|
|
111
|
-
resolvePublicFile('offline.html')
|
|
112
|
-
)
|
|
104
|
+
fs.copyFileSync(path.resolve(offlinePath), resolvePublicFile('offline.html'))
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
if (offlinePageExists || staticsCacheOnly) {
|
|
@@ -126,31 +118,19 @@ compiler.run(async (error, stats) => {
|
|
|
126
118
|
|
|
127
119
|
const importScripts = offlineConfig.importScripts || []
|
|
128
120
|
|
|
129
|
-
const stringImportScripts = importScripts
|
|
130
|
-
.map(url => `importScripts("${url}")`)
|
|
131
|
-
.join('\n')
|
|
121
|
+
const stringImportScripts = importScripts.map(url => `importScripts("${url}")`).join('\n')
|
|
132
122
|
|
|
133
|
-
Boolean(importScripts.length) &&
|
|
134
|
-
console.log('\nExternal Scripts Added to the SW:\n', stringImportScripts)
|
|
123
|
+
Boolean(importScripts.length) && console.log('\nExternal Scripts Added to the SW:\n', stringImportScripts)
|
|
135
124
|
|
|
136
125
|
// read the service worker template
|
|
137
|
-
const swTemplate = fs.readFileSync(
|
|
138
|
-
path.resolve(__dirname, '..', 'service-worker.js'),
|
|
139
|
-
'utf-8'
|
|
140
|
-
)
|
|
126
|
+
const swTemplate = fs.readFileSync(path.resolve(__dirname, '..', 'service-worker.js'), 'utf-8')
|
|
141
127
|
|
|
142
128
|
// replace all the variables from the template with the actual values
|
|
143
129
|
const swCode = swTemplate
|
|
144
130
|
.replace('// IMPORT_SCRIPTS_HERE', stringImportScripts)
|
|
145
131
|
.replace("require('static-manifest')", JSON.stringify(manifestStatics))
|
|
146
|
-
.replace(
|
|
147
|
-
|
|
148
|
-
JSON.stringify(Date.now().toString())
|
|
149
|
-
)
|
|
150
|
-
.replace(
|
|
151
|
-
"require('static-statics-cache-only')",
|
|
152
|
-
JSON.stringify(staticsCacheOnly)
|
|
153
|
-
)
|
|
132
|
+
.replace("require('static-cache-name')", JSON.stringify(Date.now().toString()))
|
|
133
|
+
.replace("require('static-statics-cache-only')", JSON.stringify(staticsCacheOnly))
|
|
154
134
|
|
|
155
135
|
const swFilePath = resolvePublicFile('service-worker.js')
|
|
156
136
|
|
|
@@ -158,9 +138,7 @@ compiler.run(async (error, stats) => {
|
|
|
158
138
|
console.log('\nService worker generated succesfully!\n')
|
|
159
139
|
}
|
|
160
140
|
|
|
161
|
-
log.success(
|
|
162
|
-
`Your app is compiled in ${process.env.NODE_ENV} mode in /public. It's ready to roll!`
|
|
163
|
-
)
|
|
141
|
+
log.success(`Your app is compiled in ${process.env.NODE_ENV} mode in /public. It's ready to roll!`)
|
|
164
142
|
|
|
165
143
|
compiler.close(closeErr => {
|
|
166
144
|
const exitCode = closeErr ? 1 : 0
|
package/bin/sui-bundler-dev.js
CHANGED
|
@@ -28,10 +28,7 @@ const DEFAULT_WATCH = !CI
|
|
|
28
28
|
if (!module.parent) {
|
|
29
29
|
program
|
|
30
30
|
.option('-c, --context [folder]', 'Context folder (cwd by default)')
|
|
31
|
-
.option(
|
|
32
|
-
'-L, --link-all [monorepo]',
|
|
33
|
-
'Link all packages inside of monorepo multipackage'
|
|
34
|
-
)
|
|
31
|
+
.option('-L, --link-all [monorepo]', 'Link all packages inside of monorepo multipackage')
|
|
35
32
|
.option(
|
|
36
33
|
'-l, --link-package [package]',
|
|
37
34
|
'Replace each occurrence of this package with an absolute path to this folder',
|
|
@@ -41,11 +38,7 @@ if (!module.parent) {
|
|
|
41
38
|
},
|
|
42
39
|
[]
|
|
43
40
|
)
|
|
44
|
-
.option(
|
|
45
|
-
'-w, --watch',
|
|
46
|
-
'Watch files and restart the server on change',
|
|
47
|
-
DEFAULT_WATCH
|
|
48
|
-
)
|
|
41
|
+
.option('-w, --watch', 'Watch files and restart the server on change', DEFAULT_WATCH)
|
|
49
42
|
.on('--help', () => {
|
|
50
43
|
console.log(' Examples:')
|
|
51
44
|
console.log('')
|
|
@@ -61,21 +54,11 @@ if (!module.parent) {
|
|
|
61
54
|
webpackConfig.context = context || webpackConfig.context
|
|
62
55
|
}
|
|
63
56
|
|
|
64
|
-
const start = async ({
|
|
65
|
-
config = webpackConfig,
|
|
66
|
-
packagesToLink = program.opts().linkPackage || []
|
|
67
|
-
} = {}) => {
|
|
57
|
+
const start = async ({config = webpackConfig, packagesToLink = program.opts().linkPackage || []} = {}) => {
|
|
68
58
|
clearConsole()
|
|
69
59
|
// Warn and crash if required files are missing
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
path.join(config.context, 'index.html'),
|
|
73
|
-
path.join(config.context, 'app.js')
|
|
74
|
-
])
|
|
75
|
-
) {
|
|
76
|
-
log.error(
|
|
77
|
-
`✖ Required files are missing, create and index.html and app.js inside your src folder.`
|
|
78
|
-
)
|
|
60
|
+
if (!checkRequiredFiles([path.join(config.context, 'index.html')])) {
|
|
61
|
+
log.error(`✖ Required files are missing, create and index.html and app.js inside your src folder.`)
|
|
79
62
|
process.exit(1)
|
|
80
63
|
}
|
|
81
64
|
|
package/bin/sui-bundler-lib.js
CHANGED
|
@@ -16,10 +16,7 @@ program
|
|
|
16
16
|
.option('-o, --output [output]', 'Bundle folder path')
|
|
17
17
|
.option('-u, --umd [libraryName]', 'Whether to output library as umb')
|
|
18
18
|
.option('-r, --root', 'Create build in root dir instead of version subdir')
|
|
19
|
-
.option(
|
|
20
|
-
'-p, --path [path]',
|
|
21
|
-
'Absolute public path where files will be located.'
|
|
22
|
-
)
|
|
19
|
+
.option('-p, --path [path]', 'Absolute public path where files will be located.')
|
|
23
20
|
.on('--help', () =>
|
|
24
21
|
console.log(`Examples:
|
|
25
22
|
$ sui-bundler lib src/index.js -o umd/my-lib -p http://my-cdn.com/my-lib -C'
|
|
@@ -48,12 +45,7 @@ if (!publicPath) {
|
|
|
48
45
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
49
46
|
|
|
50
47
|
const version = getPackageJson(process.cwd()).version
|
|
51
|
-
const outputFolder = path.join(
|
|
52
|
-
process.cwd(),
|
|
53
|
-
output,
|
|
54
|
-
path.sep,
|
|
55
|
-
root ? '' : version
|
|
56
|
-
)
|
|
48
|
+
const outputFolder = path.join(process.cwd(), output, path.sep, root ? '' : version)
|
|
57
49
|
const webpackConfig = {...config, entry: path.resolve(process.cwd(), entry)}
|
|
58
50
|
webpackConfig.output.publicPath = publicPath + (root ? '' : version + '/')
|
|
59
51
|
webpackConfig.output.path = outputFolder
|
|
@@ -94,7 +86,5 @@ webpack(webpackConfig).run((error, stats) => {
|
|
|
94
86
|
}
|
|
95
87
|
|
|
96
88
|
console.log(`Webpack stats: ${stats}`)
|
|
97
|
-
log.success(
|
|
98
|
-
`Your library is compiled in production mode in: \n${outputFolder}`
|
|
99
|
-
)
|
|
89
|
+
log.success(`Your library is compiled in production mode in: \n${outputFolder}`)
|
|
100
90
|
})
|
package/bin/sui-bundler.js
CHANGED
|
@@ -9,9 +9,6 @@ program
|
|
|
9
9
|
.command('dev', 'open a server dev to start the development')
|
|
10
10
|
.command('build', 'Compile all assets and create a public folder')
|
|
11
11
|
.command('lib', 'Compile a library to a bundle with chunks.')
|
|
12
|
-
.command(
|
|
13
|
-
'analyzer',
|
|
14
|
-
'Compile all assets and create a HTML inspector for your bundle'
|
|
15
|
-
)
|
|
12
|
+
.command('analyzer', 'Compile all assets and create a HTML inspector for your bundle')
|
|
16
13
|
|
|
17
14
|
program.parse(process.argv)
|
|
@@ -32,9 +32,7 @@ module.exports = (config, urls) => {
|
|
|
32
32
|
|
|
33
33
|
// Log the correct message of compilation depending if we have warnings
|
|
34
34
|
if (isSuccessful) {
|
|
35
|
-
stats.hasWarnings()
|
|
36
|
-
? log.warn('⚠ Compiled with warnings')
|
|
37
|
-
: log.success('✔ Compiled successfully')
|
|
35
|
+
stats.hasWarnings() ? log.warn('⚠ Compiled with warnings') : log.success('✔ Compiled successfully')
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
// Even with warnings, we show instructions to access localhost if we have a compilation
|
|
@@ -52,9 +50,7 @@ module.exports = (config, urls) => {
|
|
|
52
50
|
|
|
53
51
|
// With warnings, even after showing the instructions we must list the warnings we have
|
|
54
52
|
if (stats.hasWarnings()) {
|
|
55
|
-
const messages = formatWebpackMessages(
|
|
56
|
-
stats.toJson('errors-warnings', true)
|
|
57
|
-
)
|
|
53
|
+
const messages = formatWebpackMessages(stats.toJson('errors-warnings', true))
|
|
58
54
|
log.warn(messages.warnings.join('\n\n'))
|
|
59
55
|
}
|
|
60
56
|
})
|
|
@@ -46,9 +46,7 @@ async function externalsManifestLoader(source) {
|
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
48
|
const manifest = await getRemoteManifest(
|
|
49
|
-
typeof manifestURL === 'string'
|
|
50
|
-
? manifestURL
|
|
51
|
-
: manifestURL[process.env.NODE_ENV]
|
|
49
|
+
typeof manifestURL === 'string' ? manifestURL : manifestURL[process.env.NODE_ENV]
|
|
52
50
|
)
|
|
53
51
|
const entries = Object.entries(manifest)
|
|
54
52
|
const nextSource = entries.reduce((acc, entry) => {
|
|
@@ -14,9 +14,7 @@ const diccFromAbsolutePaths = (paths, init = {}) =>
|
|
|
14
14
|
log.success(`✔ ${pkg.name} from path "${packagePath}"`)
|
|
15
15
|
return acc
|
|
16
16
|
} catch (e) {
|
|
17
|
-
log.warn(
|
|
18
|
-
`⚠ Package from path "${packagePath}" can't be linked.\n Path is wrong or package.json is missing.`
|
|
19
|
-
)
|
|
17
|
+
log.warn(`⚠ Package from path "${packagePath}" can't be linked.\n Path is wrong or package.json is missing.`)
|
|
20
18
|
return acc
|
|
21
19
|
}
|
|
22
20
|
}, init)
|
|
@@ -24,11 +22,7 @@ const diccFromAbsolutePaths = (paths, init = {}) =>
|
|
|
24
22
|
const absolutePathForMonoRepo = base => {
|
|
25
23
|
if (!base) return []
|
|
26
24
|
return fg
|
|
27
|
-
.sync([
|
|
28
|
-
`${path.resolve(base)}/**/package.json`,
|
|
29
|
-
'!**/node_modules/**',
|
|
30
|
-
'!**/lib/**'
|
|
31
|
-
])
|
|
25
|
+
.sync([`${path.resolve(base)}/**/package.json`, '!**/node_modules/**', '!**/lib/**'])
|
|
32
26
|
.map(p => path.dirname(p))
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -49,7 +43,7 @@ module.exports = ({config, packagesToLink, linkAll}) => {
|
|
|
49
43
|
* if neccesary
|
|
50
44
|
*/
|
|
51
45
|
const linkLoader = {
|
|
52
|
-
test: /\.(jsx?|scss)$/,
|
|
46
|
+
test: /\.(jsx?|tsx?|scss)$/,
|
|
53
47
|
enforce: 'pre', // this will ensure is execute before transformations
|
|
54
48
|
use: {
|
|
55
49
|
loader: require.resolve('./LinkLoader'),
|
|
@@ -8,10 +8,7 @@ const createSassLinkImporter = entryPoints => url => {
|
|
|
8
8
|
const [org, name] = url.split(/\//)
|
|
9
9
|
const pkg = [org.replace('~', ''), name].join('/')
|
|
10
10
|
|
|
11
|
-
const absoluteUrl = url.replace(
|
|
12
|
-
new RegExp(`~?${pkg}(\\/lib)?`, 'g'),
|
|
13
|
-
entryPoints[pkg]
|
|
14
|
-
)
|
|
11
|
+
const absoluteUrl = url.replace(new RegExp(`~?${pkg}(\\/lib)?`, 'g'), entryPoints[pkg])
|
|
15
12
|
return {file: absoluteUrl}
|
|
16
13
|
}
|
|
17
14
|
return null
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.45.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,10 +22,13 @@
|
|
|
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",
|
|
27
|
-
"
|
|
29
|
+
"@swc/core": "1.3.14",
|
|
30
|
+
"@swc/helpers": "0.4.12",
|
|
31
|
+
"address": "1.2.2",
|
|
28
32
|
"autoprefixer": "10.4.8",
|
|
29
33
|
"babel-loader": "8.2.5",
|
|
30
34
|
"babel-preset-sui": "3",
|
|
@@ -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,6 +50,7 @@
|
|
|
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",
|
|
@@ -0,0 +1,48 @@
|
|
|
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()
|
package/service-worker.js
CHANGED
|
@@ -50,9 +50,7 @@ const copyResponse = async function (response) {
|
|
|
50
50
|
statusText: clonedResponse.statusText
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const body = canConstructResponseFromBodyStream()
|
|
54
|
-
? clonedResponse.body
|
|
55
|
-
: await clonedResponse.blob()
|
|
53
|
+
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob()
|
|
56
54
|
|
|
57
55
|
return new Response(body, responseInit)
|
|
58
56
|
}
|
package/shared/config.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/* Extract sui-bundler from package.json -> "config": {"sui-bundler": { ... }} */
|
|
2
|
-
const {
|
|
3
|
-
config: packageJsonConfig = {}
|
|
4
|
-
} = require(`${process.cwd()}/package.json`)
|
|
2
|
+
const {config: packageJsonConfig = {}} = require(`${process.cwd()}/package.json`)
|
|
5
3
|
|
|
6
4
|
const {'sui-bundler': config = {}} = packageJsonConfig
|
|
7
|
-
const {
|
|
8
|
-
extractComments = false,
|
|
9
|
-
sourcemaps,
|
|
10
|
-
supportLegacyBrowsers = true
|
|
11
|
-
} = config
|
|
5
|
+
const {extractComments = false, sourcemaps, supportLegacyBrowsers = true} = config
|
|
12
6
|
|
|
13
7
|
exports.config = config
|
|
14
8
|
exports.supportLegacyBrowsers = supportLegacyBrowsers
|
package/shared/define.js
CHANGED
|
@@ -6,9 +6,23 @@ 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
|
-
|
|
14
|
-
|
|
22
|
+
__MOCKS_API_PATH__: JSON.stringify(process.env.MOCKS_API_PATH || process.env.PWD + '/mocks/routes'),
|
|
23
|
+
...vars,
|
|
24
|
+
...Object.fromEntries(Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)]))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new webpack.DefinePlugin(definitions)
|
|
28
|
+
}
|
package/shared/index.js
CHANGED
|
@@ -19,9 +19,7 @@ class InlineChunkHtmlPlugin {
|
|
|
19
19
|
if (tag.tagName !== 'script' || !(tag.attributes && tag.attributes.src)) {
|
|
20
20
|
return tag
|
|
21
21
|
}
|
|
22
|
-
const scriptName = publicPath
|
|
23
|
-
? tag.attributes.src.replace(publicPath, '')
|
|
24
|
-
: tag.attributes.src
|
|
22
|
+
const scriptName = publicPath ? tag.attributes.src.replace(publicPath, '') : tag.attributes.src
|
|
25
23
|
if (!this.tests.some(test => scriptName.match(test))) {
|
|
26
24
|
return tag
|
|
27
25
|
}
|
|
@@ -39,8 +37,7 @@ class InlineChunkHtmlPlugin {
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
compiler.hooks.compilation.tap('InlineChunkHtmlPlugin', compilation => {
|
|
42
|
-
const tagFunction = tag =>
|
|
43
|
-
this.getInlinedTag(publicPath, compilation.assets, tag)
|
|
40
|
+
const tagFunction = tag => this.getInlinedTag(publicPath, compilation.assets, tag)
|
|
44
41
|
|
|
45
42
|
const hooks = this.htmlWebpackPlugin.getHooks(compilation)
|
|
46
43
|
hooks.alterAssetTagGroups.tap('InlineChunkHtmlPlugin', assets => {
|
package/shared/minify-js.js
CHANGED
|
@@ -22,6 +22,4 @@ const terserMinifier = ({extractComments, sourceMap}) =>
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
module.exports = ({extractComments, sourceMap}) =>
|
|
25
|
-
supportLegacyBrowsers
|
|
26
|
-
? terserMinifier({extractComments, sourceMap})
|
|
27
|
-
: esbuildMinifier({sourceMap})
|
|
25
|
+
supportLegacyBrowsers ? terserMinifier({extractComments, sourceMap}) : esbuildMinifier({sourceMap})
|
|
@@ -0,0 +1,69 @@
|
|
|
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/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,31 +12,37 @@ 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)) return path.resolve(path.join(PWDNodeModules, pkgName))
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
try {
|
|
29
|
+
return require.resolve(pkgName).replace(/\/index\.js$/, '')
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return ''
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
const mustPackagesToAlias = {}
|
|
36
|
+
|
|
28
37
|
exports.defaultAlias = Object.fromEntries(
|
|
29
|
-
defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)])
|
|
38
|
+
defaultPackagesToAlias.map(pkgName => [pkgName, createAliasPath(pkgName)]).filter(([, path]) => path)
|
|
30
39
|
)
|
|
31
40
|
|
|
32
41
|
const aliasFromConfig = config.alias
|
|
33
42
|
? Object.entries(config.alias).reduce(
|
|
34
43
|
(obj, [aliasName, aliasPath]) => ({
|
|
35
44
|
...obj,
|
|
36
|
-
[aliasName]: aliasPath.startsWith('./')
|
|
37
|
-
? path.join(PWD, aliasPath)
|
|
38
|
-
: aliasPath
|
|
45
|
+
[aliasName]: aliasPath.startsWith('./') ? path.join(PWD, aliasPath) : aliasPath
|
|
39
46
|
}),
|
|
40
47
|
{}
|
|
41
48
|
)
|
package/shared/resolve-loader.js
CHANGED
package/tsconfig.json
ADDED
|
@@ -51,11 +51,7 @@ function prepareUrls(protocol, host, port, pathname = '/') {
|
|
|
51
51
|
if (lanUrlForConfig) {
|
|
52
52
|
// Check if the address is a private ip
|
|
53
53
|
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
|
|
54
|
-
if (
|
|
55
|
-
/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
|
|
56
|
-
lanUrlForConfig
|
|
57
|
-
)
|
|
58
|
-
) {
|
|
54
|
+
if (/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(lanUrlForConfig)) {
|
|
59
55
|
// Address is private, format it for later use
|
|
60
56
|
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig)
|
|
61
57
|
} else {
|
|
@@ -94,21 +90,11 @@ function printInstructions(appName, urls, useYarn) {
|
|
|
94
90
|
|
|
95
91
|
console.log()
|
|
96
92
|
console.log('Note that the development build is not optimized.')
|
|
97
|
-
console.log(
|
|
98
|
-
`To create a production build, use ` +
|
|
99
|
-
`${cyan(`${useYarn ? 'yarn' : 'npm run'} build`)}.`
|
|
100
|
-
)
|
|
93
|
+
console.log(`To create a production build, use ` + `${cyan(`${useYarn ? 'yarn' : 'npm run'} build`)}.`)
|
|
101
94
|
console.log()
|
|
102
95
|
}
|
|
103
96
|
|
|
104
|
-
function createCompiler({
|
|
105
|
-
appName,
|
|
106
|
-
config,
|
|
107
|
-
urls,
|
|
108
|
-
useYarn,
|
|
109
|
-
useTypeScript,
|
|
110
|
-
webpack
|
|
111
|
-
}) {
|
|
97
|
+
function createCompiler({appName, config, urls, useYarn, useTypeScript, webpack}) {
|
|
112
98
|
// "Compiler" is a low-level interface to webpack.
|
|
113
99
|
// It lets us listen to some events and provide our own custom messages.
|
|
114
100
|
let compiler
|
|
@@ -181,11 +167,7 @@ function createCompiler({
|
|
|
181
167
|
console.log(messages.warnings.join('\n\n'))
|
|
182
168
|
|
|
183
169
|
// Teach some ESLint tricks.
|
|
184
|
-
console.log(
|
|
185
|
-
`\nSearch for the ${yellow(
|
|
186
|
-
'keywords'
|
|
187
|
-
)} to learn more about each warning.`
|
|
188
|
-
)
|
|
170
|
+
console.log(`\nSearch for the ${yellow('keywords')} to learn more about each warning.`)
|
|
189
171
|
}
|
|
190
172
|
})
|
|
191
173
|
|
|
@@ -221,13 +203,9 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
|
|
|
221
203
|
if (!proxy) return undefined
|
|
222
204
|
|
|
223
205
|
if (typeof proxy !== 'string') {
|
|
224
|
-
console.log(
|
|
225
|
-
red('When specified, "proxy" in package.json must be a string.')
|
|
226
|
-
)
|
|
206
|
+
console.log(red('When specified, "proxy" in package.json must be a string.'))
|
|
227
207
|
console.log(red('Instead, the type of "proxy" was "' + typeof proxy + '".'))
|
|
228
|
-
console.log(
|
|
229
|
-
red('Either remove "proxy" from package.json, or make it a string.')
|
|
230
|
-
)
|
|
208
|
+
console.log(red('Either remove "proxy" from package.json, or make it a string.'))
|
|
231
209
|
process.exit(1)
|
|
232
210
|
}
|
|
233
211
|
|
|
@@ -237,23 +215,15 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
|
|
|
237
215
|
const sockPath = process.env.WDS_SOCKET_PATH || '/ws'
|
|
238
216
|
const isDefaultSockHost = !process.env.WDS_SOCKET_HOST
|
|
239
217
|
function mayProxy(pathname) {
|
|
240
|
-
const maybePublicPath = path.resolve(
|
|
241
|
-
appPublicFolder,
|
|
242
|
-
pathname.replace(new RegExp('^' + servedPathname), '')
|
|
243
|
-
)
|
|
218
|
+
const maybePublicPath = path.resolve(appPublicFolder, pathname.replace(new RegExp('^' + servedPathname), ''))
|
|
244
219
|
const isPublicFileRequest = fs.existsSync(maybePublicPath)
|
|
245
220
|
// used by webpackHotDevClient
|
|
246
|
-
const isWdsEndpointRequest =
|
|
247
|
-
isDefaultSockHost && pathname.startsWith(sockPath)
|
|
221
|
+
const isWdsEndpointRequest = isDefaultSockHost && pathname.startsWith(sockPath)
|
|
248
222
|
return !(isPublicFileRequest || isWdsEndpointRequest)
|
|
249
223
|
}
|
|
250
224
|
|
|
251
225
|
if (!/^http(s)?:\/\//.test(proxy)) {
|
|
252
|
-
console.log(
|
|
253
|
-
red(
|
|
254
|
-
'When "proxy" is specified in package.json it must start with either http:// or https://'
|
|
255
|
-
)
|
|
256
|
-
)
|
|
226
|
+
console.log(red('When "proxy" is specified in package.json it must start with either http:// or https://'))
|
|
257
227
|
process.exit(1)
|
|
258
228
|
}
|
|
259
229
|
|
|
@@ -276,9 +246,7 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
|
|
|
276
246
|
context: function (pathname, req) {
|
|
277
247
|
return (
|
|
278
248
|
req.method !== 'GET' ||
|
|
279
|
-
(mayProxy(pathname) &&
|
|
280
|
-
req.headers.accept &&
|
|
281
|
-
req.headers.accept.indexOf('text/html') === -1)
|
|
249
|
+
(mayProxy(pathname) && req.headers.accept && req.headers.accept.indexOf('text/html') === -1)
|
|
282
250
|
)
|
|
283
251
|
},
|
|
284
252
|
onProxyReq: proxyReq => {
|
package/utils/clearConsole.js
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
function clearConsole() {
|
|
9
|
-
process.stdout.write(
|
|
10
|
-
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
|
|
11
|
-
)
|
|
9
|
+
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H')
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
module.exports = clearConsole
|
|
@@ -34,9 +34,7 @@ function formatMessage(message) {
|
|
|
34
34
|
// Transform parsing error into syntax error
|
|
35
35
|
// TODO: move this to our ESLint formatter?
|
|
36
36
|
lines = lines.map(line => {
|
|
37
|
-
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
|
38
|
-
line
|
|
39
|
-
)
|
|
37
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line)
|
|
40
38
|
if (!parsingError) {
|
|
41
39
|
return line
|
|
42
40
|
}
|
|
@@ -46,10 +44,7 @@ function formatMessage(message) {
|
|
|
46
44
|
|
|
47
45
|
message = lines.join('\n')
|
|
48
46
|
// 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
|
-
)
|
|
47
|
+
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`)
|
|
53
48
|
// Clean up export errors
|
|
54
49
|
message = message.replace(
|
|
55
50
|
/^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
|
|
@@ -76,17 +71,14 @@ function formatMessage(message) {
|
|
|
76
71
|
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
|
77
72
|
lines = [
|
|
78
73
|
lines[0],
|
|
79
|
-
lines[1]
|
|
80
|
-
.replace('Error: ', '')
|
|
81
|
-
.replace('Module not found: Cannot find file:', 'Cannot find file:')
|
|
74
|
+
lines[1].replace('Error: ', '').replace('Module not found: Cannot find file:', 'Cannot find file:')
|
|
82
75
|
]
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
// Add helpful message for users trying to use Sass for the first time
|
|
86
79
|
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
87
80
|
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.'
|
|
81
|
+
lines[1] += 'Run `npm install sass` or `yarn add sass` inside your workspace.'
|
|
90
82
|
}
|
|
91
83
|
|
|
92
84
|
message = lines.join('\n')
|
|
@@ -94,18 +86,12 @@ function formatMessage(message) {
|
|
|
94
86
|
// exception of stacks containing `webpack:` because they're normally
|
|
95
87
|
// from user code generated by webpack. For more information see
|
|
96
88
|
// 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
|
|
89
|
+
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, '') // at ... ...:x:y
|
|
101
90
|
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, '') // at <anonymous>
|
|
102
91
|
lines = message.split('\n')
|
|
103
92
|
|
|
104
93
|
// Remove duplicated newlines
|
|
105
|
-
lines = lines.filter(
|
|
106
|
-
(line, index, arr) =>
|
|
107
|
-
index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
|
|
108
|
-
)
|
|
94
|
+
lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim())
|
|
109
95
|
|
|
110
96
|
// Reassemble the message
|
|
111
97
|
message = lines.join('\n')
|
|
@@ -21,11 +21,7 @@ const execOptions = {
|
|
|
21
21
|
* @returns {string} The process id
|
|
22
22
|
*/
|
|
23
23
|
function getProcessIdOnPort(port) {
|
|
24
|
-
return execFileSync(
|
|
25
|
-
'lsof',
|
|
26
|
-
[`-i:${port}`, '-P', '-t', '-sTCP:LISTEN'],
|
|
27
|
-
execOptions
|
|
28
|
-
)
|
|
24
|
+
return execFileSync('lsof', [`-i:${port}`, '-P', '-t', '-sTCP:LISTEN'], execOptions)
|
|
29
25
|
.split('\n')[0]
|
|
30
26
|
.trim()
|
|
31
27
|
}
|
|
@@ -36,10 +32,7 @@ function getProcessIdOnPort(port) {
|
|
|
36
32
|
* @returns {string} - The process name
|
|
37
33
|
*/
|
|
38
34
|
function getProcessCommand(processId) {
|
|
39
|
-
const command = execSync(
|
|
40
|
-
'ps -o command -p ' + processId + ' | sed -n 2p',
|
|
41
|
-
execOptions
|
|
42
|
-
)
|
|
35
|
+
const command = execSync('ps -o command -p ' + processId + ' | sed -n 2p', execOptions)
|
|
43
36
|
|
|
44
37
|
return command.replace(/\n$/, '')
|
|
45
38
|
}
|
|
@@ -50,10 +43,7 @@ function getProcessCommand(processId) {
|
|
|
50
43
|
* @returns {string} - The process directory
|
|
51
44
|
*/
|
|
52
45
|
function getDirectoryOfProcessById(processId) {
|
|
53
|
-
return execSync(
|
|
54
|
-
`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`,
|
|
55
|
-
execOptions
|
|
56
|
-
).trim()
|
|
46
|
+
return execSync(`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`, execOptions).trim()
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
/**
|
|
@@ -67,12 +57,7 @@ function getProcessForPort(port) {
|
|
|
67
57
|
const directory = getDirectoryOfProcessById(processId)
|
|
68
58
|
const command = getProcessCommand(processId)
|
|
69
59
|
|
|
70
|
-
return (
|
|
71
|
-
bold(command) +
|
|
72
|
-
gray(' (pid ' + processId + ')\n') +
|
|
73
|
-
gray(' in ') +
|
|
74
|
-
cyan(directory)
|
|
75
|
-
)
|
|
60
|
+
return bold(command) + gray(' (pid ' + processId + ')\n') + gray(' in ') + cyan(directory)
|
|
76
61
|
} catch (e) {
|
|
77
62
|
return null
|
|
78
63
|
}
|
package/utils/ignoredFiles.js
CHANGED
|
@@ -13,10 +13,5 @@ const path = require('path')
|
|
|
13
13
|
const escape = require('escape-string-regexp')
|
|
14
14
|
|
|
15
15
|
module.exports = function ignoredFiles(appSrc) {
|
|
16
|
-
return new RegExp(
|
|
17
|
-
`^(?!${escape(
|
|
18
|
-
path.normalize(appSrc + '/').replace(/[\\]+/g, '/')
|
|
19
|
-
)}).+/node_modules/`,
|
|
20
|
-
'g'
|
|
21
|
-
)
|
|
16
|
+
return new RegExp(`^(?!${escape(path.normalize(appSrc + '/').replace(/[\\]+/g, '/'))}).+/node_modules/`, 'g')
|
|
22
17
|
}
|
package/webpack.config.dev.js
CHANGED
|
@@ -5,20 +5,14 @@ const webpack = require('webpack')
|
|
|
5
5
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
6
6
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
envVars,
|
|
10
|
-
MAIN_ENTRY_POINT,
|
|
11
|
-
config,
|
|
12
|
-
cleanList,
|
|
13
|
-
when
|
|
14
|
-
} = require('./shared/index.js')
|
|
8
|
+
const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/index.js')
|
|
15
9
|
const definePlugin = require('./shared/define.js')
|
|
16
10
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
17
11
|
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
18
12
|
const {supportLegacyBrowsers} = require('./shared/config.js')
|
|
19
13
|
|
|
20
14
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
21
|
-
const
|
|
15
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
22
16
|
|
|
23
17
|
const outputPath = path.join(process.cwd(), 'dist')
|
|
24
18
|
|
|
@@ -47,7 +41,7 @@ const webpackConfig = {
|
|
|
47
41
|
timers: false
|
|
48
42
|
},
|
|
49
43
|
modules: ['node_modules', path.resolve(process.cwd())],
|
|
50
|
-
extensions: ['.js', '.json']
|
|
44
|
+
extensions: ['.js', '.tsx', '.ts', '.json']
|
|
51
45
|
},
|
|
52
46
|
stats: 'errors-only',
|
|
53
47
|
entry: {
|
|
@@ -87,7 +81,7 @@ const webpackConfig = {
|
|
|
87
81
|
resolveLoader,
|
|
88
82
|
module: {
|
|
89
83
|
rules: cleanList([
|
|
90
|
-
|
|
84
|
+
createCompilerRules({supportLegacyBrowsers, isDevelopment: true}),
|
|
91
85
|
{
|
|
92
86
|
test: /(\.css|\.scss)$/,
|
|
93
87
|
use: cleanList([
|
|
@@ -114,14 +108,11 @@ const webpackConfig = {
|
|
|
114
108
|
require.resolve('@s-ui/sass-loader')
|
|
115
109
|
])
|
|
116
110
|
},
|
|
117
|
-
when(config['externals-manifest'], () =>
|
|
118
|
-
manifestLoaderRules(config['externals-manifest'])
|
|
119
|
-
)
|
|
111
|
+
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
|
|
120
112
|
])
|
|
121
113
|
},
|
|
122
114
|
watch: !CI,
|
|
123
|
-
devtool:
|
|
124
|
-
config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
|
|
115
|
+
devtool: config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
|
|
125
116
|
}
|
|
126
117
|
|
|
127
118
|
module.exports = webpackConfig
|
package/webpack.config.lib.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
const webpack = require('webpack')
|
|
2
2
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
3
|
-
const {
|
|
4
|
-
cleanList,
|
|
5
|
-
envVars,
|
|
6
|
-
MAIN_ENTRY_POINT,
|
|
7
|
-
config
|
|
8
|
-
} = require('./shared/index.js')
|
|
3
|
+
const {cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.js')
|
|
9
4
|
const path = require('path')
|
|
10
5
|
const minifyJs = require('./shared/minify-js.js')
|
|
11
6
|
const definePlugin = require('./shared/define.js')
|
|
12
|
-
const
|
|
7
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
13
8
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
14
|
-
const {
|
|
15
|
-
extractComments,
|
|
16
|
-
sourceMap,
|
|
17
|
-
supportLegacyBrowsers
|
|
18
|
-
} = require('./shared/config.js')
|
|
9
|
+
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
|
|
19
10
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
20
11
|
|
|
21
12
|
const cssFileName = 'styles.css'
|
|
@@ -54,7 +45,7 @@ module.exports = {
|
|
|
54
45
|
},
|
|
55
46
|
plugins: cleanList([
|
|
56
47
|
new webpack.ProvidePlugin({
|
|
57
|
-
process: 'process/browser'
|
|
48
|
+
process: 'process/browser.js'
|
|
58
49
|
}),
|
|
59
50
|
new MiniCssExtractPlugin({
|
|
60
51
|
filename: cssFileName,
|
|
@@ -67,6 +58,6 @@ module.exports = {
|
|
|
67
58
|
definePlugin()
|
|
68
59
|
]),
|
|
69
60
|
module: {
|
|
70
|
-
rules: [
|
|
61
|
+
rules: [createCompilerRules({supportLegacyBrowsers}), sassRules]
|
|
71
62
|
}
|
|
72
63
|
}
|
package/webpack.config.prod.js
CHANGED
|
@@ -9,21 +9,11 @@ const {WebpackManifestPlugin} = require('webpack-manifest-plugin')
|
|
|
9
9
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
10
10
|
const InlineChunkHtmlPlugin = require('./shared/inline-chunk-html-plugin.js')
|
|
11
11
|
|
|
12
|
-
const {
|
|
13
|
-
when,
|
|
14
|
-
cleanList,
|
|
15
|
-
envVars,
|
|
16
|
-
MAIN_ENTRY_POINT,
|
|
17
|
-
config
|
|
18
|
-
} = require('./shared/index.js')
|
|
12
|
+
const {when, cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.js')
|
|
19
13
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
20
|
-
const {
|
|
21
|
-
extractComments,
|
|
22
|
-
sourceMap,
|
|
23
|
-
supportLegacyBrowsers
|
|
24
|
-
} = require('./shared/config.js')
|
|
14
|
+
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
|
|
25
15
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
26
|
-
const
|
|
16
|
+
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
27
17
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
28
18
|
const definePlugin = require('./shared/define.js')
|
|
29
19
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
@@ -34,13 +24,9 @@ const CWD = process.cwd()
|
|
|
34
24
|
const PUBLIC_PATH = process.env.CDN || config.cdn || '/'
|
|
35
25
|
const PWD = process.env.PWD ?? ''
|
|
36
26
|
|
|
37
|
-
const filename = config.onlyHash
|
|
38
|
-
? '[contenthash:8].js'
|
|
39
|
-
: '[name].[contenthash:8].js'
|
|
27
|
+
const filename = config.onlyHash ? '[contenthash:8].js' : '[name].[contenthash:8].js'
|
|
40
28
|
|
|
41
|
-
const cssFileName = config.onlyHash
|
|
42
|
-
? '[contenthash:8].css'
|
|
43
|
-
: '[name].[contenthash:8].css'
|
|
29
|
+
const cssFileName = config.onlyHash ? '[contenthash:8].css' : '[name].[contenthash:8].css'
|
|
44
30
|
|
|
45
31
|
const target = supportLegacyBrowsers ? ['web', 'es5'] : 'web'
|
|
46
32
|
|
|
@@ -54,7 +40,7 @@ const webpackConfig = {
|
|
|
54
40
|
context: path.resolve(CWD, 'src'),
|
|
55
41
|
resolve: {
|
|
56
42
|
alias: {...aliasFromConfig},
|
|
57
|
-
extensions: ['.js', '.json'],
|
|
43
|
+
extensions: ['.js', '.json', '.ts', '.tsx'],
|
|
58
44
|
modules: ['node_modules', path.resolve(CWD)],
|
|
59
45
|
fallback: {
|
|
60
46
|
assert: false,
|
|
@@ -77,14 +63,12 @@ const webpackConfig = {
|
|
|
77
63
|
optimization: {
|
|
78
64
|
checkWasmTypes: false,
|
|
79
65
|
minimize: true,
|
|
80
|
-
minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(
|
|
81
|
-
Boolean
|
|
82
|
-
),
|
|
66
|
+
minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(Boolean),
|
|
83
67
|
runtimeChunk: true
|
|
84
68
|
},
|
|
85
69
|
plugins: cleanList([
|
|
86
70
|
new webpack.ProvidePlugin({
|
|
87
|
-
process: 'process/browser'
|
|
71
|
+
process: 'process/browser.js'
|
|
88
72
|
}),
|
|
89
73
|
new webpack.ids.HashedModuleIdsPlugin(),
|
|
90
74
|
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
@@ -114,11 +98,9 @@ const webpackConfig = {
|
|
|
114
98
|
]),
|
|
115
99
|
module: {
|
|
116
100
|
rules: cleanList([
|
|
117
|
-
|
|
101
|
+
createCompilerRules({supportLegacyBrowsers}),
|
|
118
102
|
sassRules,
|
|
119
|
-
when(config['externals-manifest'], () =>
|
|
120
|
-
manifestLoaderRules(config['externals-manifest'])
|
|
121
|
-
)
|
|
103
|
+
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
|
|
122
104
|
])
|
|
123
105
|
},
|
|
124
106
|
resolveLoader
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const webpack = require('webpack')
|
|
5
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
6
|
+
const {WebpackManifestPlugin} = require('webpack-manifest-plugin')
|
|
7
|
+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
|
|
8
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
9
|
+
|
|
10
|
+
const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/index.js')
|
|
11
|
+
const definePlugin = require('./shared/define.js')
|
|
12
|
+
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
13
|
+
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
14
|
+
const {supportLegacyBrowsers} = require('./shared/config.js')
|
|
15
|
+
|
|
16
|
+
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
17
|
+
const createBabelRules = require('./shared/module-rules-babel.js')
|
|
18
|
+
|
|
19
|
+
const outputPath = path.join(process.cwd(), '.sui/public')
|
|
20
|
+
|
|
21
|
+
const {CI = false, PWD = '', CDN} = process.env
|
|
22
|
+
|
|
23
|
+
process.env.NODE_ENV = 'development'
|
|
24
|
+
|
|
25
|
+
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
26
|
+
|
|
27
|
+
const webpackConfig = {
|
|
28
|
+
mode: 'development',
|
|
29
|
+
context: path.resolve(PWD, 'src'),
|
|
30
|
+
resolve: {
|
|
31
|
+
alias: {
|
|
32
|
+
...defaultAlias,
|
|
33
|
+
...aliasFromConfig
|
|
34
|
+
},
|
|
35
|
+
fallback: {
|
|
36
|
+
fs: false,
|
|
37
|
+
http: require.resolve('stream-http'),
|
|
38
|
+
https: require.resolve('https-browserify'),
|
|
39
|
+
buffer: require.resolve('buffer/'),
|
|
40
|
+
url: require.resolve('url/'),
|
|
41
|
+
stream: false,
|
|
42
|
+
zlib: false,
|
|
43
|
+
timers: false
|
|
44
|
+
},
|
|
45
|
+
modules: ['node_modules', path.resolve(process.cwd())],
|
|
46
|
+
extensions: ['.js', '.json']
|
|
47
|
+
},
|
|
48
|
+
stats: 'errors-only',
|
|
49
|
+
entry: {
|
|
50
|
+
app: [`webpack-hot-middleware/client?path=${CDN}__webpack_hmr`, MAIN_ENTRY_POINT]
|
|
51
|
+
},
|
|
52
|
+
target: 'web',
|
|
53
|
+
optimization: {
|
|
54
|
+
checkWasmTypes: false,
|
|
55
|
+
emitOnErrors: false,
|
|
56
|
+
removeAvailableModules: false,
|
|
57
|
+
removeEmptyChunks: false,
|
|
58
|
+
runtimeChunk: true,
|
|
59
|
+
splitChunks: false
|
|
60
|
+
},
|
|
61
|
+
output: {
|
|
62
|
+
path: outputPath,
|
|
63
|
+
pathinfo: false,
|
|
64
|
+
publicPath: CDN
|
|
65
|
+
},
|
|
66
|
+
plugins: [
|
|
67
|
+
new webpack.ProvidePlugin({
|
|
68
|
+
process: 'process/browser.js'
|
|
69
|
+
}),
|
|
70
|
+
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
71
|
+
definePlugin({__DEV__: true}),
|
|
72
|
+
new MiniCssExtractPlugin(),
|
|
73
|
+
new HtmlWebpackPlugin({
|
|
74
|
+
template: './index.html',
|
|
75
|
+
inject: true,
|
|
76
|
+
env: process.env
|
|
77
|
+
}),
|
|
78
|
+
new WebpackManifestPlugin({fileName: 'asset-manifest.json'}),
|
|
79
|
+
new webpack.HotModuleReplacementPlugin(),
|
|
80
|
+
new ReactRefreshWebpackPlugin({overlay: false})
|
|
81
|
+
],
|
|
82
|
+
resolveLoader,
|
|
83
|
+
module: {
|
|
84
|
+
rules: cleanList([
|
|
85
|
+
createBabelRules({supportLegacyBrowsers, isDevelopment: true}),
|
|
86
|
+
{
|
|
87
|
+
test: /(\.css|\.scss)$/,
|
|
88
|
+
use: cleanList([
|
|
89
|
+
MiniCssExtractPlugin.loader,
|
|
90
|
+
require.resolve('css-loader'),
|
|
91
|
+
when(config['externals-manifest'], () => ({
|
|
92
|
+
loader: 'externals-manifest-loader',
|
|
93
|
+
options: {
|
|
94
|
+
manifestURL: config['externals-manifest']
|
|
95
|
+
}
|
|
96
|
+
})),
|
|
97
|
+
{
|
|
98
|
+
loader: require.resolve('postcss-loader'),
|
|
99
|
+
options: {
|
|
100
|
+
postcssOptions: {
|
|
101
|
+
plugins: [
|
|
102
|
+
require('autoprefixer')({
|
|
103
|
+
overrideBrowserslist: config.targets
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
require.resolve('@s-ui/sass-loader')
|
|
110
|
+
])
|
|
111
|
+
},
|
|
112
|
+
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
|
|
113
|
+
])
|
|
114
|
+
},
|
|
115
|
+
watch: !CI,
|
|
116
|
+
devtool: config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = webpackConfig
|
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)$/,
|
|
@@ -48,9 +48,7 @@ const webpackConfig = {
|
|
|
48
48
|
dataUrl: () => ''
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
-
when(config['externals-manifest'], () =>
|
|
52
|
-
manifestLoaderRules(config['externals-manifest'])
|
|
53
|
-
)
|
|
51
|
+
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
|
|
54
52
|
])
|
|
55
53
|
}
|
|
56
54
|
}
|
|
@@ -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
|
-
})
|