Skip to content

Commit d432792

Browse files
committed
feat: 👯 Support multiple webpack builds
1 parent c93634d commit d432792

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

packages/accurapp-scripts/scripts/build.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ if (process.env.PUBLIC_URL.endsWith('/')) {
2525
}
2626

2727
const appDir = process.cwd()
28-
const config = readWebpackConfig()
2928
const appPublic = path.resolve(appDir, 'public')
30-
const appBuild = config.output.path
29+
const appBuild = path.resolve(appDir, 'build')
3130
const relativeAppBuildPath = `${path.relative(appDir, appBuild)}/`
3231

3332
function clearBuildFolder() {

packages/accurapp-scripts/scripts/start.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ function runDevServer(port) {
3838
log.info(`Or on your network at: ${chalk.cyan(urls.lanUrlForTerminal)}`)
3939
})
4040

41+
const webpackConfig = readWebpackConfig()
4142
const devServerConfig = {
4243
host: HOST,
4344
public: urls.lanUrlForConfig,
4445
https: PROTOCOL === 'https',
45-
...readWebpackConfig().devServer,
46+
...(Array.isArray(webpackConfig) ? webpackConfig[0] : webpackConfig).devServer,
4647
}
4748
const devServer = new WebpackDevServer(compiler, devServerConfig)
4849
devServer.listen(port, HOST, (err) => {

packages/accurapp-scripts/utils/logging-utils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ function printFileSizes(webpackStats, appBuild, maxBundleGzipSize = 1024 * 1024)
110110
.toJson({ all: false, assets: true })
111111
.assets.filter((asset) => /\.(js|css)$/.test(asset.name))
112112
.map((asset) => {
113-
const fileContents = fs.readFileSync(path.join(appBuild, asset.name))
114-
const size = fs.statSync(path.join(appBuild, asset.name)).size
113+
const file = path.join(appBuild, asset.name)
114+
115+
// Maybe some files are in a subfolder
116+
if (!fs.existsSync(file)) {
117+
return
118+
}
119+
120+
const fileContents = fs.readFileSync(file)
121+
const size = fs.statSync(file).size
115122
const sizeGzip = gzipSize(fileContents)
116123

117124
return {
@@ -121,6 +128,7 @@ function printFileSizes(webpackStats, appBuild, maxBundleGzipSize = 1024 * 1024)
121128
sizeGzip,
122129
}
123130
})
131+
.filter(Boolean)
124132
)
125133
.reduce((single, all) => all.concat(single), [])
126134

packages/accurapp-scripts/utils/webpack-utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ function createWebpackCompiler(onFirstReadyCallback = () => {}, onError = () =>
7373
timings: true,
7474
})
7575

76+
// If there's an array of configs
77+
if (statsData.children) {
78+
const totalTime = statsData.children.reduce((sum, s) => sum + s.time, 0)
79+
statsData.time = totalTime
80+
}
81+
7682
if (useTypeScript && statsData.errors.length === 0) {
7783
// push typescript errors and warnings
7884
const messages = await tsMessagesPromise

0 commit comments

Comments
 (0)