Nuxt/lib/builder/webpack/plugins/vue/util.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

const { red, yellow } = require('chalk')
const prefix = `[vue-server-renderer-webpack-plugin]`
const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`)) // eslint-disable-line no-console
const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`)) // eslint-disable-line no-console
exports.validate = compiler => {
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.'
)
}
}
exports.onEmit = (compiler, name, hook) => {
if (compiler.hooks) {
// Webpack >= 4.0.0
compiler.hooks.emit.tap(name,
(compilation) => new Promise((resolve, reject) => {
try {
hook(compilation, resolve)
} catch (e) {
reject(e)
}
}))
} else {
// Webpack < 4.0.0
compiler.plugin('emit', hook)
}
}
exports.isJS = (file) => /\.js(\?[^.]+)?$/.test(file)
exports.isCSS = (file) => /\.css(\?[^.]+)?$/.test(file)