提交 e4962592 编写于 作者: fxy060608's avatar fxy060608

refactor(cli): improve find vue-loader logic

上级 0e14398f
......@@ -96,7 +96,7 @@ const rules = [{
babelrc: false
}
},
jsPreprocessorLoader
jsPreprocessorLoader
],
exclude (modulePath) {
return excludeModuleReg.test(modulePath) && modulePath.indexOf('@dcloudio') === -1
......
......@@ -2,8 +2,8 @@ const loaderUtils = require('loader-utils')
module.exports = function(content) {
this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const vueLoaderOptions = this.loaders.find(loader => loader.ident)
if (vueLoaderOptions && vueLoaderOptions && vueLoaderOptions.ident === 'vue-loader-options') {
const params = loaderUtils.parseQuery(this.resourceQuery)
if (params.recyclable) {
Object.assign(vueLoaderOptions.options.compilerOptions, {
......
......@@ -5,8 +5,8 @@ const loaderUtils = require('loader-utils')
module.exports = function(content) {
this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const vueLoaderOptions = this.loaders.find(loader => loader.ident)
if (vueLoaderOptions && vueLoaderOptions.ident === 'vue-loader-options') {
const params = loaderUtils.parseQuery(this.resourceQuery)
/* eslint-disable no-mixed-operators */
const filterModules = JSON.parse(params && params['filter-modules'] || '{}')
......
......@@ -32,8 +32,8 @@ const filterTagName = getPlatformFilterTag() || ''
module.exports = function (content) {
this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const vueLoaderOptions = this.loaders.find(loader => loader.ident)
if (vueLoaderOptions && vueLoaderOptions.ident === 'vue-loader-options') {
const globalUsingComponents = getGlobalUsingComponents()
const realResourcePath = path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)
const resourcePath = normalizeNodeModules(removeExt(realResourcePath) + templateExt)
......
......@@ -25,8 +25,8 @@ module.exports = function (content) {
if (process.env.UNI_USING_COMPONENTS) {
// 向 uni-template-compier 传递 emitFile
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const vueLoaderOptions = this.loaders.find(loader => loader.ident)
if (vueLoaderOptions && vueLoaderOptions.ident === 'vue-loader-options') {
Object.assign(vueLoaderOptions.options.compilerOptions, {
resourcePath: removeExt(realResourcePath) + templateExt,
emitFile: this.emitFile
......@@ -57,8 +57,8 @@ module.exports = function (content) {
cacheCompilerOptions(realResourcePath, compilerOptions)
// 向 vue-loader templateLoader 传递 compilerOptions
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const vueLoaderOptions = this.loaders.find(loader => loader.ident)
if (vueLoaderOptions && vueLoaderOptions.ident === 'vue-loader-options') {
Object.assign(vueLoaderOptions.options.compilerOptions, compilerOptions)
} else {
throw new Error('vue-loader-options parse error')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册