File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,18 @@ const genStylesCode = require('./codegen/styleInjection')
10
10
const { genHotReloadCode } = require ( './codegen/hotReload' )
11
11
const genCustomBlocksCode = require ( './codegen/customBlocks' )
12
12
const componentNormalizerPath = require . resolve ( './runtime/componentNormalizer' )
13
+ const { NS } = require ( './plugin' )
13
14
14
15
module . exports = function ( source ) {
15
16
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
+
16
25
const stringifyRequest = r => loaderUtils . stringifyRequest ( loaderContext , r )
17
26
18
27
const {
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' )
2
+ const path = require ( 'path' )
1
3
const qs = require ( 'querystring' )
2
4
const RuleSet = require ( 'webpack/lib/RuleSet' )
3
5
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 {
6
10
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
+
7
28
// get a hold of the raw rules
8
29
const rawRules = compiler . options . module . rules
9
30
// use webpack's RuleSet utility to normalize user rules
@@ -175,3 +196,6 @@ function cleanIdent (use) {
175
196
}
176
197
return use
177
198
}
199
+
200
+ VueLoaderPlugin . NS = NS
201
+ module . exports = VueLoaderPlugin
You can’t perform that action at this time.
0 commit comments