Skip to content

Commit 068bb81

Browse files
committed
fix: warn missing plugin
1 parent 949ba66 commit 068bb81

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Diff for: lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ const genStylesCode = require('./codegen/styleInjection')
1010
const { genHotReloadCode } = require('./codegen/hotReload')
1111
const genCustomBlocksCode = require('./codegen/customBlocks')
1212
const componentNormalizerPath = require.resolve('./runtime/componentNormalizer')
13+
const { NS } = require('./plugin')
1314

1415
module.exports = function (source) {
1516
const loaderContext = this
17+
18+
if (!loaderContext[NS]) {
19+
loaderContext.emitError(new Error(
20+
`vue-loader was used without the corresponding plugin. ` +
21+
`Make sure to include VueLoaderPlugin in your webpack config.`
22+
))
23+
}
24+
1625
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
1726

1827
const {

Diff for: lib/plugin.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
const fs = require('fs')
2+
const path = require('path')
13
const qs = require('querystring')
24
const RuleSet = require('webpack/lib/RuleSet')
35

4-
// TODO handle vueRule with oneOf
5-
module.exports = class VueLoaderPlugin {
6+
const id = 'vue-loader-plugin'
7+
const NS = path.dirname(fs.realpathSync(__filename))
8+
9+
class VueLoaderPlugin {
610
apply (compiler) {
11+
// add NS marker so that the loader can detect and report missing plugin
12+
if (compiler.hooks) {
13+
// webpack 4
14+
compiler.hooks.compilation.tap(id, compilation => {
15+
compilation.hooks.normalModuleLoader.tap(id, loaderContext => {
16+
loaderContext[NS] = true
17+
})
18+
})
19+
} else {
20+
// webpack < 4
21+
compiler.plugin('compilation', compilation => {
22+
compilation.plugin('normal-module-loader', loaderContext => {
23+
loaderContext[NS] = true
24+
})
25+
})
26+
}
27+
728
// get a hold of the raw rules
829
const rawRules = compiler.options.module.rules
930
// use webpack's RuleSet utility to normalize user rules
@@ -175,3 +196,6 @@ function cleanIdent (use) {
175196
}
176197
return use
177198
}
199+
200+
VueLoaderPlugin.NS = NS
201+
module.exports = VueLoaderPlugin

0 commit comments

Comments
 (0)