2018-03-16 16:12:06 +00:00
|
|
|
import chalk from 'chalk'
|
2018-03-16 07:48:29 +00:00
|
|
|
|
|
|
|
const prefix = `[vue-server-renderer-webpack-plugin]`
|
2018-03-16 16:12:06 +00:00
|
|
|
export const warn = msg => console.error(chalk.red(`${prefix} ${msg}\n`)) // eslint-disable-line no-console
|
|
|
|
export const tip = msg => console.log(chalk.yellow(`${prefix} ${msg}\n`)) // eslint-disable-line no-console
|
2018-03-16 07:48:29 +00:00
|
|
|
|
2018-03-16 16:12:06 +00:00
|
|
|
export const validate = compiler => {
|
2018-03-16 07:48:29 +00:00
|
|
|
if (compiler.options.target !== 'node') {
|
|
|
|
warn('webpack config `target` should be "node".')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {
|
|
|
|
warn('webpack config `output.libraryTarget` should be "commonjs2".')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!compiler.options.externals) {
|
|
|
|
tip(
|
|
|
|
'It is recommended to externalize dependencies in the server build for ' +
|
|
|
|
'better build performance.'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 16:12:06 +00:00
|
|
|
export const onEmit = (compiler, name, hook) => {
|
2018-03-16 07:48:29 +00:00
|
|
|
if (compiler.hooks) {
|
|
|
|
// Webpack >= 4.0.0
|
2018-03-16 19:03:11 +00:00
|
|
|
compiler.hooks.emit.tapAsync(name, hook)
|
2018-03-16 07:48:29 +00:00
|
|
|
} else {
|
|
|
|
// Webpack < 4.0.0
|
|
|
|
compiler.plugin('emit', hook)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:42:31 +00:00
|
|
|
export const isJS = file => /\.js(\?[^.]+)?$/.test(file)
|
2018-03-16 07:48:29 +00:00
|
|
|
|
2018-07-20 15:42:31 +00:00
|
|
|
export const isCSS = file => /\.css(\?[^.]+)?$/.test(file)
|