@s-ui/bundler 9.47.0 → 9.49.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.
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
const webpack = require('webpack')
|
|
2
2
|
const formatWebpackMessages = require('../utils/formatWebpackMessages.js')
|
|
3
|
+
const {printInstructions} = require('../utils/WebpackDevServerUtils.js')
|
|
3
4
|
const clearConsole = require('../utils/clearConsole.js')
|
|
4
5
|
const log = require('../shared/log.js')
|
|
5
6
|
|
|
6
7
|
const isInteractive = process.stdout.isTTY
|
|
7
8
|
|
|
8
|
-
const printInstructions = ({urls}) =>
|
|
9
|
-
log.info(`
|
|
10
|
-
Local: ${urls.localUrlForTerminal}
|
|
11
|
-
Network: ${urls.lanUrlForTerminal}
|
|
12
|
-
`)
|
|
13
|
-
|
|
14
9
|
module.exports = (config, urls) => {
|
|
15
10
|
let compiler
|
|
16
11
|
try {
|
package/package.json
CHANGED
|
@@ -16,10 +16,9 @@ const url = require('url')
|
|
|
16
16
|
const {findFreePorts, isFreePort} = require('find-free-ports')
|
|
17
17
|
|
|
18
18
|
const clearConsole = require('./clearConsole.js')
|
|
19
|
-
const formatWebpackMessages = require('./formatWebpackMessages.js')
|
|
20
19
|
const getProcessForPort = require('./getProcessForPort.js')
|
|
21
20
|
|
|
22
|
-
const {bold, cyan, green,
|
|
21
|
+
const {bold, cyan, green, red} = require('@s-ui/helpers/colors')
|
|
23
22
|
|
|
24
23
|
const isInteractive = process.stdout.isTTY
|
|
25
24
|
|
|
@@ -76,9 +75,8 @@ function prepareUrls(protocol, host, port, pathname = '/') {
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
function printInstructions(
|
|
80
|
-
console.log()
|
|
81
|
-
console.log(`You can now view ${bold(appName)} in the browser.`)
|
|
78
|
+
function printInstructions({urls}) {
|
|
79
|
+
console.log(`You can now view the app in the browser.`)
|
|
82
80
|
console.log()
|
|
83
81
|
|
|
84
82
|
if (urls.lanUrlForTerminal) {
|
|
@@ -90,90 +88,10 @@ function printInstructions(appName, urls, useYarn) {
|
|
|
90
88
|
|
|
91
89
|
console.log()
|
|
92
90
|
console.log('Note that the development build is not optimized.')
|
|
93
|
-
console.log(
|
|
91
|
+
console.log('To create a production build, use npm run build')
|
|
94
92
|
console.log()
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
function createCompiler({appName, config, urls, useYarn, useTypeScript, webpack}) {
|
|
98
|
-
// "Compiler" is a low-level interface to webpack.
|
|
99
|
-
// It lets us listen to some events and provide our own custom messages.
|
|
100
|
-
let compiler
|
|
101
|
-
try {
|
|
102
|
-
compiler = webpack(config)
|
|
103
|
-
} catch (err) {
|
|
104
|
-
console.log(red('Failed to compile.'))
|
|
105
|
-
console.log()
|
|
106
|
-
console.log(err.message || err)
|
|
107
|
-
console.log()
|
|
108
|
-
process.exit(1)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// "invalid" event fires when you have changed a file, and webpack is
|
|
112
|
-
// recompiling a bundle. WebpackDevServer takes care to pause serving the
|
|
113
|
-
// bundle, so if you refresh, it'll wait instead of serving the old one.
|
|
114
|
-
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
|
|
115
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
|
116
|
-
if (isInteractive) {
|
|
117
|
-
clearConsole()
|
|
118
|
-
}
|
|
119
|
-
console.log('Compiling...')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
let isFirstCompile = true
|
|
123
|
-
|
|
124
|
-
// "done" event fires when webpack has finished recompiling the bundle.
|
|
125
|
-
// Whether or not you have warnings or errors, you will get this event.
|
|
126
|
-
compiler.hooks.done.tap('done', async stats => {
|
|
127
|
-
if (isInteractive) clearConsole()
|
|
128
|
-
|
|
129
|
-
// We have switched off the default webpack output in WebpackDevServer
|
|
130
|
-
// options so we are going to "massage" the warnings and errors and present
|
|
131
|
-
// them in a readable focused way.
|
|
132
|
-
// We only construct the warnings and errors for speed:
|
|
133
|
-
// https://github.com/facebook/create-react-app/issues/4492#issuecomment-421959548
|
|
134
|
-
const statsData = stats.toJson({
|
|
135
|
-
all: false,
|
|
136
|
-
warnings: true,
|
|
137
|
-
errors: true
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
const messages = formatWebpackMessages(statsData)
|
|
141
|
-
const isSuccessful = !messages.errors.length && !messages.warnings.length
|
|
142
|
-
if (isSuccessful) {
|
|
143
|
-
console.log(green('Compiled successfully!'))
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (isSuccessful && (isInteractive || isFirstCompile)) {
|
|
147
|
-
printInstructions(appName, urls, useYarn)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
isFirstCompile = false
|
|
151
|
-
|
|
152
|
-
// If errors exist, only show errors.
|
|
153
|
-
if (messages.errors.length) {
|
|
154
|
-
// Only keep the first error. Others are often indicative
|
|
155
|
-
// of the same problem, but confuse the reader with noise.
|
|
156
|
-
if (messages.errors.length > 1) {
|
|
157
|
-
messages.errors.length = 1
|
|
158
|
-
}
|
|
159
|
-
console.log(red('Failed to compile.\n'))
|
|
160
|
-
console.log(messages.errors.join('\n\n'))
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Show warnings if no errors were found.
|
|
165
|
-
if (messages.warnings.length) {
|
|
166
|
-
console.log(yellow('Compiled with warnings.\n'))
|
|
167
|
-
console.log(messages.warnings.join('\n\n'))
|
|
168
|
-
|
|
169
|
-
// Teach some ESLint tricks.
|
|
170
|
-
console.log(`\nSearch for the ${yellow('keywords')} to learn more about each warning.`)
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
return compiler
|
|
175
|
-
}
|
|
176
|
-
|
|
177
95
|
// We need to provide a custom onError function for httpProxyMiddleware.
|
|
178
96
|
// It allows us to log custom error messages on the console.
|
|
179
97
|
function onProxyError(proxy) {
|
|
@@ -287,7 +205,7 @@ async function choosePort(defaultPort) {
|
|
|
287
205
|
|
|
288
206
|
module.exports = {
|
|
289
207
|
choosePort,
|
|
290
|
-
|
|
208
|
+
printInstructions,
|
|
291
209
|
prepareProxy,
|
|
292
210
|
prepareUrls
|
|
293
211
|
}
|
package/webpack.config.dev.js
CHANGED
package/webpack.config.server.js
CHANGED
|
@@ -41,7 +41,7 @@ const webpackConfig = {
|
|
|
41
41
|
cache: {
|
|
42
42
|
type: 'filesystem',
|
|
43
43
|
cacheDirectory,
|
|
44
|
-
compression: !isProduction ? '
|
|
44
|
+
compression: !isProduction ? 'gzip' : false
|
|
45
45
|
},
|
|
46
46
|
externals: [webpackNodeExternals()],
|
|
47
47
|
plugins: [new webpack.DefinePlugin({'global.GENTLY': false})],
|