@@ -3,6 +3,7 @@ var assign = require('object-assign')
3
3
var parse = require ( './parser' )
4
4
var hash = require ( 'hash-sum' )
5
5
var path = require ( 'path' )
6
+ var normalizeDepPath = require ( './normalize-dep' )
6
7
7
8
var defaultLang = {
8
9
template : 'html' ,
@@ -12,7 +13,9 @@ var defaultLang = {
12
13
13
14
var rewriterInjectRE = / \b ( c s s (?: - l o a d e r ) ? (?: \? [ ^ ! ] + ) ? ) (?: ! | $ ) /
14
15
var selectorPath = 'vue-loader/lib/selector'
15
- var templateLoader = 'vue-loader/lib/template-loader'
16
+ var templateLoaderPath = 'vue-loader/lib/template-loader'
17
+ var styleLoaderPath = normalizeDepPath ( 'vue-style-loader' )
18
+ var hotReloadAPIPath = normalizeDepPath ( 'vue-hot-reload-api' )
16
19
17
20
module . exports = function ( content ) {
18
21
this . cacheable ( )
@@ -24,25 +27,18 @@ module.exports = function (content) {
24
27
var moduleId = '_v-' + hash ( filePath )
25
28
var styleRewriter = 'vue-loader/lib/style-rewriter?id=' + moduleId
26
29
27
- var defaultLoaders = {
28
- html : 'vue-loader/lib/template-compiler?id=' + moduleId ,
29
- css : 'vue-style-loader!css-loader' ,
30
- js : 'babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false'
31
- }
32
-
33
- // respect user babel options
34
- if ( this . options . babel ) {
35
- defaultLoaders . js = 'babel-loader'
36
- }
37
-
38
- // enable css source map if needed
39
- if (
30
+ var needCssSourceMap =
40
31
this . sourceMap &&
41
32
! this . minimize &&
42
- options . cssSourceMap !== false &&
43
- process . env . NODE_ENV !== 'production'
44
- ) {
45
- defaultLoaders . css = 'vue-style-loader!css-loader?sourceMap'
33
+ process . env . NODE_ENV !== 'production' &&
34
+ options . cssSourceMap !== false
35
+
36
+ var defaultLoaders = {
37
+ html : 'vue-loader/lib/template-compiler?id=' + moduleId ,
38
+ css : styleLoaderPath + '!css-loader' + ( needCssSourceMap ? '?sourceMap' : '' ) ,
39
+ js : this . options . babel
40
+ ? 'babel-loader' // respect user options
41
+ : 'babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false'
46
42
}
47
43
48
44
// check if there are custom loaders specified via
@@ -102,7 +98,7 @@ module.exports = function (content) {
102
98
// unknown lang, infer the loader to be used
103
99
switch ( type ) {
104
100
case 'template' :
105
- return defaultLoaders . html + '!' + templateLoader + '?raw&engine=' + lang + '!'
101
+ return defaultLoaders . html + '!' + templateLoaderPath + '?raw&engine=' + lang + '!'
106
102
case 'styles' :
107
103
return defaultLoaders . css + '!' + rewriter + lang + '!'
108
104
case 'script' :
@@ -198,7 +194,7 @@ module.exports = function (content) {
198
194
) {
199
195
output +=
200
196
'\nif (module.hot) {(function () {' +
201
- ' var hotAPI = require("vue-hot-reload-api ")\n' +
197
+ ' var hotAPI = require("' + hotReloadAPIPath + ' ")\n' +
202
198
' hotAPI.install(require("vue"), false)\n' +
203
199
' if (!hotAPI.compatible) return\n' +
204
200
' module.hot.accept()\n' +
0 commit comments