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

refactor(cli): improve find vue-loader logic

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