From 5c9dacd9603f54dcd41d40136dfbf080a7baa400 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 25 May 2017 22:02:51 +1200 Subject: [PATCH 1/2] fix: don't mutate this.options --- lib/loader.js | 46 ++++++++++++++++----------- lib/style-compiler/index.js | 11 +++---- lib/template-compiler/index.js | 5 ++- lib/template-compiler/preprocessor.js | 2 +- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 72339c7d..06fa844b 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -49,7 +49,7 @@ module.exports = function (content) { var loaderContext = this var query = loaderUtils.getOptions(this) || {} - var options = this.options.__vueOptions__ = Object.assign({}, this.options.vue, this.vue, query) + var options = Object.assign({}, this.options.vue, this.vue, query) var rawRequest = getRawRequest(this, options.excludedPreLoaders) var filePath = this.resourcePath @@ -70,16 +70,21 @@ module.exports = function (content) { ? '?' + JSON.stringify(options.buble) : '' - var templateCompilerOptions = '?' + JSON.stringify({ - id: moduleId, - transformToRequire: options.transformToRequire, - preserveWhitespace: options.preserveWhitespace, - buble: options.buble, - // only pass compilerModules if it's a path string - compilerModules: typeof options.compilerModules === 'string' - ? options.compilerModules - : undefined - }) + var templateCompilerOptions = '?' + JSON.stringify( + Object.assign({}, + query, + { + id: moduleId, + transformToRequire: options.transformToRequire, + preserveWhitespace: options.preserveWhitespace, + buble: options.buble, + // only pass compilerModules if it's a path string + compilerModules: typeof options.compilerModules === 'string' + ? options.compilerModules + : undefined + } + ) + ) var defaultLoaders = { html: templateCompilerPath + templateCompilerOptions, @@ -196,13 +201,18 @@ module.exports = function (content) { var styleCompiler = '' if (type === 'styles') { // style compiler that needs to be applied for all styles - styleCompiler = styleCompilerPath + '?' + JSON.stringify({ - // a marker for vue-style-loader to know that this is an import from a vue file - vue: true, - id: moduleId, - scoped: !!scoped, - hasInlineConfig: !!query.postcss - }) + '!' + styleCompiler = styleCompilerPath + '?' + JSON.stringify( + Object.assign({}, + query, + { + // a marker for vue-style-loader to know that this is an import from a vue file + vue: true, + id: moduleId, + scoped: !!scoped, + hasInlineConfig: !!query.postcss + } + ) + ) + '!' // normalize scss/sass if no specific loaders have been provided if (!loaders[lang]) { if (lang === 'sass') { diff --git a/lib/style-compiler/index.js b/lib/style-compiler/index.js index a2c9bf35..567367d4 100644 --- a/lib/style-compiler/index.js +++ b/lib/style-compiler/index.js @@ -9,10 +9,10 @@ module.exports = function (css, map) { this.cacheable() var cb = this.async() - var query = loaderUtils.getOptions(this) || {} - var vueOptions = this.options.__vueOptions__ + var query = Object.assign({}, loaderUtils.getOptions(this), this.options.vue, this.vue) - if (!vueOptions) { + // Slightly messy check for HappyPack as we can't use this.__vueoptions__ anymore + if (this._compiler.constructor.name === 'HappyFakeCompiler') { if (query.hasInlineConfig) { this.emitError( `\n [vue-loader] It seems you are using HappyPack with inline postcss ` + @@ -22,10 +22,9 @@ module.exports = function (css, map) { `\n See http://vue-loader.vuejs.org/en/features/postcss.html#using-a-config-file for more details.\n` ) } - vueOptions = Object.assign({}, this.options.vue, this.vue) } - loadPostcssConfig(this, vueOptions.postcss).then(config => { + loadPostcssConfig(this, query.postcss).then(config => { var plugins = [trim].concat(config.plugins) var options = Object.assign({ to: this.resourcePath, @@ -42,7 +41,7 @@ module.exports = function (css, map) { if ( this.sourceMap && !this.minimize && - vueOptions.cssSourceMap !== false && + query.cssSourceMap !== false && process.env.NODE_ENV !== 'production' && !options.map ) { diff --git a/lib/template-compiler/index.js b/lib/template-compiler/index.js index bfc7a146..198b10d3 100644 --- a/lib/template-compiler/index.js +++ b/lib/template-compiler/index.js @@ -10,11 +10,10 @@ module.exports = function (html) { this.cacheable() var isServer = this.target === 'node' var isProduction = this.minimize || process.env.NODE_ENV === 'production' - var vueOptions = this.options.__vueOptions__ || {} - var options = loaderUtils.getOptions(this) || {} + var options = Object.assign({}, loaderUtils.getOptions(this), this.options.vue, this.vue) var defaultModules = [transformRequire(options.transformToRequire)] - var userModules = vueOptions.compilerModules || options.compilerModules + var userModules = options.compilerModules // for HappyPack cross-process use cases if (typeof userModules === 'string') { userModules = require(userModules) diff --git a/lib/template-compiler/preprocessor.js b/lib/template-compiler/preprocessor.js index 860b099e..dfc79fb6 100644 --- a/lib/template-compiler/preprocessor.js +++ b/lib/template-compiler/preprocessor.js @@ -11,7 +11,7 @@ module.exports = function (content) { // this is never documented and should be deprecated // but we'll keep it so we don't break stuff - var vue = this.options.__vueOptions__ + var vue = Object.assign({}, this.options.vue, this.vue) if (vue && vue.template) { for (var key in vue.template) { opt[key] = vue.template[key] From d98828b504b970b2a541e2d9f1d14b81e04c142d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 25 May 2017 22:05:47 +1200 Subject: [PATCH 2/2] Comment typo --- lib/style-compiler/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/style-compiler/index.js b/lib/style-compiler/index.js index 567367d4..ea2f01a3 100644 --- a/lib/style-compiler/index.js +++ b/lib/style-compiler/index.js @@ -11,7 +11,7 @@ module.exports = function (css, map) { var query = Object.assign({}, loaderUtils.getOptions(this), this.options.vue, this.vue) - // Slightly messy check for HappyPack as we can't use this.__vueoptions__ anymore + // Slightly messy check for HappyPack as we can't use this.options.__vueoptions__ anymore if (this._compiler.constructor.name === 'HappyFakeCompiler') { if (query.hasInlineConfig) { this.emitError(