Skip to content

Commit

Permalink
fix: vue-template-compiler can be optional if @vue/compiler-sfc prese…
Browse files Browse the repository at this point in the history
…nts (vuejs#5123)
  • Loading branch information
sodatea authored and mactanxin committed Feb 11, 2020
1 parent 1c7d48f commit 4897e55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/@vue/cli-service/lib/config/base.js
Expand Up @@ -73,12 +73,21 @@ module.exports = (api, options) => {
// js is handled by cli-plugin-babel ---------------------------------------

// vue-loader --------------------------------------------------------------
const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', {
'vue-loader': require('vue-loader/package.json').version,
/* eslint-disable-next-line node/no-extraneous-require */
'@vue/component-compiler-utils': require('@vue/component-compiler-utils/package.json').version,
'vue-template-compiler': require('vue-template-compiler/package.json').version
})
const vueLoaderCacheIdentifier = {
'vue-loader': require('vue-loader/package.json').version
}

// The following 2 deps are sure to exist in Vue 2 projects.
// But once we switch to Vue 3, they're no longer mandatory.
// (In Vue 3 they are replaced by @vue/compiler-sfc)
// So wrap them in a try catch block.
try {
vueLoaderCacheIdentifier['@vue/component-compiler-utils'] =
require('@vue/component-compiler-utils/package.json').version
vueLoaderCacheIdentifier['vue-template-compiler'] =
require('vue-template-compiler/package.json').version
} catch (e) {}
const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', vueLoaderCacheIdentifier)

webpackConfig.module
.rule('vue')
Expand Down
3 changes: 3 additions & 0 deletions packages/@vue/cli-service/package.json
Expand Up @@ -94,6 +94,9 @@
},
"stylus-loader": {
"optional": true
},
"vue-template-compiler": {
"optional": true
}
},
"devDependencies": {
Expand Down

0 comments on commit 4897e55

Please sign in to comment.