mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-20 06:09:56 -06:00
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
module.exports = (api, options) => {
|
|
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
|
|
const cliServicePath = require('path').dirname(require.resolve('@vue/cli-service'))
|
|
|
|
api.chainWebpack(webpackConfig => {
|
|
const jsRule = webpackConfig.module
|
|
.rule('js')
|
|
.test(/\.jsx?$/)
|
|
.exclude
|
|
.add(filepath => {
|
|
// always trasnpile js in vue files
|
|
if (/\.vue\.jsx?$/.test(filepath)) {
|
|
return false
|
|
}
|
|
// exclude dynamic entries from cli-service
|
|
if (filepath.startsWith(cliServicePath)) {
|
|
return true
|
|
}
|
|
// check if this is something the user explicitly wants to transpile
|
|
if (options.transpileDependencies.some(dep => filepath.match(dep))) {
|
|
return false
|
|
}
|
|
// Don't transpile node_modules
|
|
return /node_modules/.test(filepath)
|
|
})
|
|
.end()
|
|
.use('cache-loader')
|
|
.loader('cache-loader')
|
|
.options(api.genCacheConfig('babel-loader', {
|
|
'@babel/core': require('@babel/core/package.json').version,
|
|
'@vue/babel-preset-app': require('@vue/babel-preset-app').version,
|
|
'babel-loader': require('babel-loader/package.json').version
|
|
}, 'babel.config.js'))
|
|
.end()
|
|
|
|
if (useThreads) {
|
|
jsRule
|
|
.use('thread-loader')
|
|
.loader('thread-loader')
|
|
}
|
|
|
|
jsRule
|
|
.use('babel-loader')
|
|
.loader('babel-loader')
|
|
})
|
|
}
|