Skip to content

Commit

Permalink
chore: webpack client and server in parallel (#9279)
Browse files Browse the repository at this point in the history
* chore: webpack client and server in parallel

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* chore: cleanup my ugly code

Signed-off-by: Matt Krick <matt.krick@gmail.com>

---------

Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick authored Dec 8, 2023
1 parent 108dc46 commit fb34aa1
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 318 deletions.
33 changes: 14 additions & 19 deletions scripts/prod.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
const webpack = require('webpack')
const makeServersConfig = require('./webpack/prod.servers.config')
const makeClientConfig = require('./webpack/prod.client.config')
const generateGraphQLArtifacts = require('./generateGraphQLArtifacts')
const cp = require('child_process')

const compile = (config, isSilent) => {
const runChild = (cmd) => {
return new Promise((resolve) => {
const cb = (err, stats) => {
if (err && !isSilent) {
console.log('Webpack error:', err)
}
const {errors} = stats.compilation
if (errors.length > 0 && !isSilent) {
console.log('PROD COMPILATION ERRORS:', errors)
}
resolve()
}
const compiler = webpack(config)
compiler.run(cb)
const build = cp.exec(cmd).on('exit', resolve)
build.stderr.pipe(process.stderr)
})
}

const prod = async (isDeploy, noDeps) => {
console.log('πŸ™πŸ™πŸ™ Building Production Server πŸ™πŸ™πŸ™')
await generateGraphQLArtifacts()
const serversConfig = makeServersConfig({isDeploy, noDeps})
const clientConfig = makeClientConfig({isDeploy: isDeploy || noDeps})
await Promise.all([compile(serversConfig), compile(clientConfig)])
await Promise.all([
runChild(
`yarn webpack --config ./scripts/webpack/prod.servers.config.js --no-stats --env=noDeps=${noDeps}`
),
runChild(
`yarn webpack --config ./scripts/webpack/prod.client.config.js --no-stats --env=isDeploy=${
isDeploy || noDeps
}`
)
])
}

if (require.main === module) {
Expand Down
Loading

0 comments on commit fb34aa1

Please sign in to comment.