@s-ui/bundler 9.39.0 → 9.40.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s-ui/bundler",
3
- "version": "9.39.0",
3
+ "version": "9.40.0",
4
4
  "description": "Config-free bundler for ES6 React apps.",
5
5
  "bin": {
6
6
  "sui-bundler": "./bin/sui-bundler.js"
@@ -50,6 +50,8 @@
50
50
  "webpack": "5.82.1",
51
51
  "webpack-dev-server": "4.10.0",
52
52
  "webpack-manifest-plugin": "5.0.0",
53
- "webpack-node-externals": "3.0.0"
53
+ "webpack-node-externals": "3.0.0",
54
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
55
+ "react-refresh": "0.14.0"
54
56
  }
55
57
  }
@@ -5,7 +5,11 @@ const EXCLUDED_FOLDERS_REGEXP = new RegExp(
5
5
  `node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
6
6
  )
7
7
 
8
- module.exports = ({isServer = false, supportLegacyBrowsers = true} = {}) => ({
8
+ module.exports = ({
9
+ isServer = false,
10
+ isDevelopment = false,
11
+ supportLegacyBrowsers = true
12
+ } = {}) => ({
9
13
  test: /\.jsx?$/,
10
14
  exclude: EXCLUDED_FOLDERS_REGEXP,
11
15
  use: [
@@ -16,6 +20,9 @@ module.exports = ({isServer = false, supportLegacyBrowsers = true} = {}) => ({
16
20
  cacheCompression: false,
17
21
  babelrc: false,
18
22
  compact: true,
23
+ plugins: [
24
+ isDevelopment && require.resolve('react-refresh/babel')
25
+ ].filter(Boolean),
19
26
  presets: [
20
27
  [
21
28
  require.resolve('babel-preset-sui'),
@@ -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', '.json']
51
51
  },
52
52
  stats: 'errors-only',
53
- entry: cleanList([
54
- require.resolve('./utils/webpackHotDevClient.js'),
55
- MAIN_ENTRY_POINT
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
- createBabelRules({supportLegacyBrowsers}),
90
+ createBabelRules({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
- }