Repository URL to install this package:
|
Version:
1.2.10 ▾
|
/**
* @file build a production output of all of our bundles.
* @see dist/dist/bundled
*/
import './setup'
import webpack from 'webpack'
import { getConfig } from '../../config/oneConfig/getConfigForEnv'
import { Configuration } from '../../typings'
import { deleteDist } from '../utils'
import { webpackConfigFactory } from './webpackConfigFactory'
export function bundle() {
const optimize = process.env.OPTIMIZE !== undefined
const ENV_INFRA = process.env.CI !== undefined
const bundles = getConfig('bundles')
const buildOutputPath = process.env.BUNDLE_SERVER_OUTPUT_PATH_ABSOLUTE
const bundleNames = Object.keys(bundles)
deleteDist(buildOutputPath)
const configs = bundleNames
.map((bundleName: 'client' | 'server') => {
const webpackConfig = webpackConfigFactory({
target: bundleName,
optimize,
})
// webpack validates all keys, this will make it hidden
Object.defineProperty(webpackConfig, 'named', {
enumerable: false,
value: bundleName,
})
return webpackConfig
})
.map((bundleConfig: Configuration) => {
bundleConfig.watch = false
/**
* @todo this works in webpack 4.5...
* @see https://webpack.js.org/concepts/mode
* @todo @fixme @perf @prod !!!!!!! THIS IS DISABLED BECAUSE THE TREE SHAKING IS MAKING SOME EXPORTS UNDEFINED
*/
bundleConfig.mode = 'none'
// bundleConfig.mode = 'production'
// bundleConfig.mode = 'development'
return { ...bundleConfig }
})
// require('fliplog').data(configs).bold('bundle configs:').echo()
const compiler = webpack(configs)
// # @todo load argv into dotenv
// # --optimize
// # --optimize-occurrence-order
// # --optimize-minimize
// # --profile
// # --verbose
// # --display-reasons
// # --display-error-details
// # --display-modules
// # --display-exclude
// # --display-chunks
// # --display=verbose
// # --progres
console.log('begining the build...')
compiler.run((compilationError, stats) => {
if (compilationError) {
throw compilationError
}
if (ENV_INFRA) {
console.log('minimal logs for CI')
} else {
const json = stats.toJson({
reasons: true,
errors: true,
modules: true,
exclude: true,
chunks: true,
verbose: true,
debug: true,
providedExports: false,
usedExports: true,
maxModules: 1000,
})
require('fliplog')
.json(json)
.bold('STATS')
.echo()
console.log(stats.toString({ colors: true }))
require('../shell/build_prod_post')
}
})
}