forked from KidkArolis/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect.js
31 lines (29 loc) · 994 Bytes
/
inspect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const fs = require('fs-extra')
const path = require('path')
const webpack = require('webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const wpConf = require('./webpack.config')
module.exports = async function (options, log) {
log.info('Generating report...')
process.env.NODE_ENV = 'production'
const webpackConfig = await wpConf(options)
webpackConfig.plugins = webpackConfig.plugins || []
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
const compiler = webpack(webpackConfig)
compiler.run(async function (err, stats) {
if (err) return console.log(err)
if (options.static && isDir(path.join(options.dir, options.static))) {
await fs.copy(path.join(options.dir, options.static), path.join(options.dir, options.dist, options.static))
}
console.log(stats.toString({
colors: true
}))
})
}
function isDir (path) {
try {
return fs.lstatSync(path).isDirectory(path)
} catch (err) {
return false
}
}