Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mutate this.options (fixes #824) #826

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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') {
Expand Down
11 changes: 5 additions & 6 deletions lib/style-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.options.__vueoptions__ anymore
if (this._compiler.constructor.name === 'HappyFakeCompiler') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I cannot review this line due to I'm not very familiar with HappyPack. 🤔
/ping @yyx990803

if (query.hasInlineConfig) {
this.emitError(
`\n [vue-loader] It seems you are using HappyPack with inline postcss ` +
Expand All @@ -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,
Expand All @@ -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
) {
Expand Down
5 changes: 2 additions & 3 deletions lib/template-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/template-compiler/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down