@s-ui/bundler 9.43.0-typescript.0 → 9.43.0-typescript.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/sui-bundler-build.js
CHANGED
|
@@ -19,6 +19,7 @@ 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')
|
|
22
23
|
.option(
|
|
23
24
|
'-l, --link-package [package]',
|
|
24
25
|
'Replace each occurrence of this package with an absolute path to this folder',
|
|
@@ -43,6 +44,7 @@ program
|
|
|
43
44
|
const {
|
|
44
45
|
clean = false,
|
|
45
46
|
context,
|
|
47
|
+
saveStats,
|
|
46
48
|
linkPackage: packagesToLink = []
|
|
47
49
|
} = program.opts()
|
|
48
50
|
|
|
@@ -88,6 +90,13 @@ compiler.run(async (error, stats) => {
|
|
|
88
90
|
|
|
89
91
|
console.log(`Webpack stats: ${stats}`)
|
|
90
92
|
|
|
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
|
+
|
|
91
100
|
const offlinePath = path.join(process.cwd(), 'src', 'offline.html')
|
|
92
101
|
const offlinePageExists = fs.existsSync(offlinePath)
|
|
93
102
|
const {offline: offlineConfig = {}} = projectConfig
|
package/bin/sui-bundler-lib.js
CHANGED
|
@@ -73,7 +73,18 @@ log.processing('Generating minified bundle...')
|
|
|
73
73
|
webpack(webpackConfig).run((error, stats) => {
|
|
74
74
|
if (error) {
|
|
75
75
|
showError(error, program)
|
|
76
|
-
|
|
76
|
+
process.exit(1)
|
|
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))
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
if (stats.hasErrors() || stats.hasWarnings()) {
|
|
@@ -86,6 +97,4 @@ webpack(webpackConfig).run((error, stats) => {
|
|
|
86
97
|
log.success(
|
|
87
98
|
`Your library is compiled in production mode in: \n${outputFolder}`
|
|
88
99
|
)
|
|
89
|
-
|
|
90
|
-
return 0
|
|
91
100
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "9.43.0-typescript.
|
|
3
|
+
"version": "9.43.0-typescript.1",
|
|
4
4
|
"description": "Config-free bundler for ES6 React apps.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sui-bundler": "./bin/sui-bundler.js"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"html-webpack-plugin": "5.5.0",
|
|
44
44
|
"https-browserify": "1.0.0",
|
|
45
45
|
"mini-css-extract-plugin": "2.6.1",
|
|
46
|
-
"postcss": "8.4.
|
|
46
|
+
"postcss": "8.4.31",
|
|
47
47
|
"postcss-loader": "7.0.1",
|
|
48
48
|
"process": "0.11.10",
|
|
49
49
|
"sass": "1.54.5",
|
|
@@ -55,6 +55,8 @@
|
|
|
55
55
|
"webpack": "5.82.1",
|
|
56
56
|
"webpack-dev-server": "4.10.0",
|
|
57
57
|
"webpack-manifest-plugin": "5.0.0",
|
|
58
|
-
"webpack-node-externals": "3.0.0"
|
|
58
|
+
"webpack-node-externals": "3.0.0",
|
|
59
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
|
60
|
+
"react-refresh": "0.14.0"
|
|
59
61
|
}
|
|
60
62
|
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -5,7 +5,6 @@ const crypto = require('crypto')
|
|
|
5
5
|
const fs = require('fs-extra')
|
|
6
6
|
const path = require('path')
|
|
7
7
|
const {writeFile} = require('@s-ui/helpers/file.js')
|
|
8
|
-
const {dynamicPackage} = require('@s-ui/helpers/packages')
|
|
9
8
|
|
|
10
9
|
const {INIT_CWD} = process.env
|
|
11
10
|
const tsConfigTemplate = `\
|
|
@@ -45,9 +44,9 @@ async function main() {
|
|
|
45
44
|
process.exit(0)
|
|
46
45
|
}
|
|
47
46
|
await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
|
|
48
|
-
await dynamicPackage('typescript')
|
|
49
47
|
console.log(
|
|
50
48
|
'❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it'
|
|
51
49
|
)
|
|
52
50
|
}
|
|
51
|
+
|
|
53
52
|
main()
|
package/shared/define.js
CHANGED
|
@@ -19,6 +19,9 @@ module.exports = (vars = {}) => {
|
|
|
19
19
|
const definitions = {
|
|
20
20
|
__DEV__: false,
|
|
21
21
|
__BASE_DIR__: JSON.stringify(process.env.PWD),
|
|
22
|
+
__MOCKS_API_PATH__: JSON.stringify(
|
|
23
|
+
process.env.MOCKS_API_PATH || process.env.PWD + '/mocks/routes'
|
|
24
|
+
),
|
|
22
25
|
...vars,
|
|
23
26
|
...Object.fromEntries(
|
|
24
27
|
Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)])
|
|
@@ -24,7 +24,11 @@ const getTSConfig = () => {
|
|
|
24
24
|
return tsConfig
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
module.exports = ({
|
|
27
|
+
module.exports = ({
|
|
28
|
+
isServer = false,
|
|
29
|
+
isDevelopment = false,
|
|
30
|
+
supportLegacyBrowsers = true
|
|
31
|
+
} = {}) => {
|
|
28
32
|
const tsConfig = getTSConfig()
|
|
29
33
|
// If TS config exists in root dir, set TypeScript as enabled.
|
|
30
34
|
const isTypeScriptEnabled = Boolean(tsConfig)
|
|
@@ -51,6 +55,9 @@ module.exports = ({isServer = false, supportLegacyBrowsers = true} = {}) => {
|
|
|
51
55
|
cacheCompression: false,
|
|
52
56
|
babelrc: false,
|
|
53
57
|
compact: true,
|
|
58
|
+
plugins: [
|
|
59
|
+
isDevelopment && require.resolve('react-refresh/babel')
|
|
60
|
+
].filter(Boolean),
|
|
54
61
|
presets: [
|
|
55
62
|
[
|
|
56
63
|
require.resolve('babel-preset-sui'),
|
package/webpack.config.dev.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
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')
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
envVars,
|
|
@@ -27,7 +28,6 @@ process.env.NODE_ENV = 'development'
|
|
|
27
28
|
|
|
28
29
|
/** @typedef {import('webpack').Configuration} WebpackConfig */
|
|
29
30
|
|
|
30
|
-
/** @type {WebpackConfig} */
|
|
31
31
|
const webpackConfig = {
|
|
32
32
|
mode: 'development',
|
|
33
33
|
context: path.resolve(PWD, 'src'),
|
|
@@ -50,10 +50,13 @@ const webpackConfig = {
|
|
|
50
50
|
extensions: ['.js', '.tsx', '.ts', '.json']
|
|
51
51
|
},
|
|
52
52
|
stats: 'errors-only',
|
|
53
|
-
entry:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
entry: {
|
|
54
|
+
app: MAIN_ENTRY_POINT
|
|
55
|
+
},
|
|
56
|
+
devServer: {
|
|
57
|
+
static: outputPath,
|
|
58
|
+
hot: true
|
|
59
|
+
},
|
|
57
60
|
target: 'web',
|
|
58
61
|
optimization: {
|
|
59
62
|
checkWasmTypes: false,
|
|
@@ -78,12 +81,13 @@ const webpackConfig = {
|
|
|
78
81
|
template: './index.html',
|
|
79
82
|
inject: true,
|
|
80
83
|
env: process.env
|
|
81
|
-
})
|
|
84
|
+
}),
|
|
85
|
+
new ReactRefreshWebpackPlugin({overlay: false})
|
|
82
86
|
],
|
|
83
87
|
resolveLoader,
|
|
84
88
|
module: {
|
|
85
89
|
rules: cleanList([
|
|
86
|
-
createCompilerRules({supportLegacyBrowsers}),
|
|
90
|
+
createCompilerRules({supportLegacyBrowsers, isDevelopment: true}),
|
|
87
91
|
{
|
|
88
92
|
test: /(\.css|\.scss)$/,
|
|
89
93
|
use: cleanList([
|
|
@@ -1,253 +0,0 @@
|
|
|
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
|
-
}
|