mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-15 13:40:59 -05:00
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
module.exports = (api, options) => {
|
|
const { genCacheConfig } = require('@vue/cli-shared-utils')
|
|
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(genCacheConfig(api, options, 'babel-loader', 'babel.config.js'))
|
|
.end()
|
|
|
|
if (useThreads) {
|
|
jsRule
|
|
.use('thread-loader')
|
|
.loader('thread-loader')
|
|
}
|
|
|
|
jsRule
|
|
.use('babel-loader')
|
|
.loader('babel-loader')
|
|
})
|
|
}
|