Nuxt/packages/webpack/src/plugins/vue/util.ts

31 lines
883 B
TypeScript
Raw Normal View History

2020-07-02 13:02:35 +00:00
/**
* This file is based on Vue.js (MIT) webpack plugins
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
*/
import { logger } from '@nuxt/kit'
import type { Compiler } from 'webpack'
2020-07-02 13:02:35 +00:00
export const validate = (compiler: Compiler) => {
2020-07-02 13:02:35 +00:00
if (compiler.options.target !== 'node') {
logger.warn('webpack config `target` should be "node".')
2020-07-02 13:02:35 +00:00
}
if (!compiler.options.externals) {
logger.info(
2020-07-02 13:02:35 +00:00
'It is recommended to externalize dependencies in the server build for ' +
'better build performance.'
)
}
}
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/
2020-07-02 13:02:35 +00:00
export const isJS = (file: string) => isJSRegExp.test(file)
2020-07-02 13:02:35 +00:00
export const extractQueryPartJS = (file: string) => isJSRegExp.exec(file)?.[1]
2020-07-02 13:02:35 +00:00
export const isCSS = (file: string) => /\.css(\?[^.]+)?$/.test(file)
export const isHotUpdate = (file: string) => file.includes('hot-update')