Commit 068bb812 authored by Evan You's avatar Evan You

fix: warn missing plugin

parent 949ba666
...@@ -10,9 +10,18 @@ const genStylesCode = require('./codegen/styleInjection') ...@@ -10,9 +10,18 @@ const genStylesCode = require('./codegen/styleInjection')
const { genHotReloadCode } = require('./codegen/hotReload') const { genHotReloadCode } = require('./codegen/hotReload')
const genCustomBlocksCode = require('./codegen/customBlocks') const genCustomBlocksCode = require('./codegen/customBlocks')
const componentNormalizerPath = require.resolve('./runtime/componentNormalizer') const componentNormalizerPath = require.resolve('./runtime/componentNormalizer')
const { NS } = require('./plugin')
module.exports = function (source) { module.exports = function (source) {
const loaderContext = this const loaderContext = this
if (!loaderContext[NS]) {
loaderContext.emitError(new Error(
`vue-loader was used without the corresponding plugin. ` +
`Make sure to include VueLoaderPlugin in your webpack config.`
))
}
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r) const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
const { const {
......
const fs = require('fs')
const path = require('path')
const qs = require('querystring') const qs = require('querystring')
const RuleSet = require('webpack/lib/RuleSet') const RuleSet = require('webpack/lib/RuleSet')
// TODO handle vueRule with oneOf const id = 'vue-loader-plugin'
module.exports = class VueLoaderPlugin { const NS = path.dirname(fs.realpathSync(__filename))
class VueLoaderPlugin {
apply (compiler) { apply (compiler) {
// add NS marker so that the loader can detect and report missing plugin
if (compiler.hooks) {
// webpack 4
compiler.hooks.compilation.tap(id, compilation => {
compilation.hooks.normalModuleLoader.tap(id, loaderContext => {
loaderContext[NS] = true
})
})
} else {
// webpack < 4
compiler.plugin('compilation', compilation => {
compilation.plugin('normal-module-loader', loaderContext => {
loaderContext[NS] = true
})
})
}
// get a hold of the raw rules // get a hold of the raw rules
const rawRules = compiler.options.module.rules const rawRules = compiler.options.module.rules
// use webpack's RuleSet utility to normalize user rules // use webpack's RuleSet utility to normalize user rules
...@@ -175,3 +196,6 @@ function cleanIdent (use) { ...@@ -175,3 +196,6 @@ function cleanIdent (use) {
} }
return use return use
} }
VueLoaderPlugin.NS = NS
module.exports = VueLoaderPlugin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment