1
+ // @todo : support hot reload
2
+ // @todo : support functional check
3
+ // @tips : not support CSS Modules
4
+ // @tips : not support CssSourceMap
5
+ // @tips : not support isServer
6
+ // @tips : not support isScoped
7
+
1
8
var loaderUtils = require ( 'loader-utils' )
2
9
var assign = require ( 'object-assign' )
3
10
var parse = require ( './parser' )
@@ -10,10 +17,12 @@ var selectorPath = normalize.lib('selector')
10
17
var templateLoaderPath = normalize . lib ( 'template-loader' )
11
18
var templateCompilerPath = normalize . lib ( 'template-compiler' )
12
19
var styleRewriterPath = normalize . lib ( 'style-rewriter' )
20
+ var styleLoaderPath = normalize . lib ( 'style-loader' )
21
+ var scriptLoaderPath = normalize . lib ( 'script-loader' )
13
22
14
23
// dep loaders
15
- var styleLoaderPath = normalize . dep ( 'vue-style-loader' )
16
- var hotReloadAPIPath = normalize . dep ( 'vue-hot-reload-api' )
24
+ // var styleLoaderPath = normalize.dep('vue-style-loader')
25
+ // var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
17
26
18
27
var hasBabel = false
19
28
try {
@@ -39,9 +48,11 @@ var checkNamedExports =
39
48
40
49
module . exports = function ( content ) {
41
50
this . cacheable ( )
42
- var isServer = this . options . target === 'node'
51
+ // var isServer = this.options.target === 'node'
52
+ // var isServer = false
43
53
var loaderContext = this
44
54
var query = loaderUtils . parseQuery ( this . query )
55
+ var params = loaderUtils . parseQuery ( this . resourceQuery )
45
56
var options = this . options . __vueOptions__ = Object . assign ( { } , this . options . vue , this . vue , query )
46
57
var filePath = this . resourcePath
47
58
var fileName = path . basename ( filePath )
@@ -50,16 +61,18 @@ module.exports = function (content) {
50
61
51
62
var isProduction = this . minimize || process . env . NODE_ENV === 'production'
52
63
53
- var needCssSourceMap =
54
- ! isProduction &&
55
- this . sourceMap &&
56
- options . cssSourceMap !== false
64
+ // var needCssSourceMap =
65
+ // !isProduction &&
66
+ // this.sourceMap &&
67
+ // options.cssSourceMap !== false
68
+ // var needCssSourceMap = false
57
69
58
70
var bubleOptions = hasBuble && options . buble ? '?' + JSON . stringify ( options . buble ) : ''
59
71
var defaultLoaders = {
60
72
html : templateCompilerPath + '?id=' + moduleId ,
61
- css : ( isServer ? '' : styleLoaderPath + '!' ) + 'css-loader' + ( needCssSourceMap ? '?sourceMap' : '' ) ,
62
- js : hasBuble ? ( 'buble-loader' + bubleOptions ) : hasBabel ? 'babel-loader' : ''
73
+ // css: (isServer ? '' : styleLoaderPath + '!') + 'css-loader' + (needCssSourceMap ? '?sourceMap' : ''),
74
+ css : styleLoaderPath ,
75
+ js : scriptLoaderPath + '!' + ( hasBuble ? ( 'buble-loader' + bubleOptions ) : hasBabel ? 'babel-loader' : '' )
63
76
}
64
77
65
78
// check if there are custom loaders specified via
@@ -185,45 +198,50 @@ module.exports = function (content) {
185
198
}
186
199
187
200
var parts = parse ( content , fileName , this . sourceMap )
188
- var hasScoped = parts . styles . some ( function ( s ) { return s . scoped } )
201
+ // var hasScoped = parts.styles.some(function (s) { return s.scoped })
189
202
var output = 'var __vue_exports__, __vue_options__\n'
190
203
191
204
// css modules
192
- output += 'var __vue_styles__ = {}\n'
193
- var cssModules = { }
205
+ // output += 'var __vue_styles__ = {}\n'
206
+ output += 'var __vue_styles__ = []\n'
207
+ // var cssModules = {}
194
208
195
209
// add requires for styles
196
210
if ( parts . styles . length ) {
197
211
output += '\n/* styles */\n'
198
212
parts . styles . forEach ( function ( style , i ) {
199
- var moduleName = ( style . module === true ) ? '$style' : style . module
213
+ // var moduleName = (style.module === true) ? '$style' : style.module
214
+ // var moduleName
200
215
201
216
// require style
202
- if ( isServer && ! moduleName ) return
217
+ // if (isServer && !moduleName) return
203
218
var requireString = style . src
204
219
? getRequireForImport ( 'styles' , style , style . scoped )
205
220
: getRequire ( 'styles' , style , i , style . scoped )
206
221
207
222
// setCssModule
208
- if ( moduleName ) {
209
- if ( moduleName in cssModules ) {
210
- loaderContext . emitError ( 'CSS module name "' + moduleName + '" is not unique!' )
211
- output += requireString
212
- } else {
213
- cssModules [ moduleName ] = true
214
-
215
- // `style-loader` exposes the name-to-hash map directly
216
- // `css-loader` exposes it in `.locals`
217
- // We drop `style-loader` in SSR, and add `.locals` here.
218
- if ( isServer ) {
219
- requireString += '.locals'
220
- }
221
-
222
- output += '__vue_styles__["' + moduleName + '"] = ' + requireString + '\n'
223
- }
224
- } else {
225
- output += requireString
226
- }
223
+ // if (moduleName) {
224
+ // if (moduleName in cssModules) {
225
+ // loaderContext.emitError('CSS module name "' + moduleName + '" is not unique!')
226
+ // output += requireString
227
+ // } else {
228
+ // cssModules[moduleName] = true
229
+
230
+ // // `style-loader` exposes the name-to-hash map directly
231
+ // // `css-loader` exposes it in `.locals`
232
+ // // We drop `style-loader` in SSR, and add `.locals` here.
233
+ // // if (isServer) {
234
+ // // requireString += '.locals'
235
+ // // }
236
+
237
+ // output += '__vue_styles__["' + moduleName + '"] = ' + requireString + '\n'
238
+ // }
239
+ // } else {
240
+ // output += requireString
241
+ // }
242
+
243
+ // output += requireString
244
+ output += '__vue_styles__.push(' + requireString + ')'
227
245
} )
228
246
}
229
247
@@ -272,53 +290,60 @@ module.exports = function (content) {
272
290
}
273
291
274
292
// attach scoped id
275
- if ( hasScoped ) {
276
- exports += '__vue_options__._scopeId = "' + moduleId + '"\n'
277
- }
278
-
279
- if ( Object . keys ( cssModules ) . length ) {
280
- // inject style modules as computed properties
281
- exports +=
282
- 'if (!__vue_options__.computed) __vue_options__.computed = {}\n' +
283
- 'Object.keys(__vue_styles__).forEach(function (key) {\n' +
284
- 'var module = __vue_styles__[key]\n' +
285
- '__vue_options__.computed[key] = function () { return module }\n' +
286
- '})\n'
287
- }
293
+ // if (hasScoped) {
294
+ // exports += '__vue_options__._scopeId = "' + moduleId + '"\n'
295
+ // }
296
+
297
+ // if (Object.keys(cssModules).length) {
298
+ // // inject style modules as computed properties
299
+ // exports +=
300
+ // 'if (!__vue_options__.computed) __vue_options__.computed = {}\n' +
301
+ // 'Object.keys(__vue_styles__).forEach(function (key) {\n' +
302
+ // 'var module = __vue_styles__[key]\n' +
303
+ // '__vue_options__.computed[key] = function () { return module }\n' +
304
+ // '})\n'
305
+ // }
306
+
307
+ exports += '__vue_options__.style = __vue_options__.style || {}\n' +
308
+ '__vue_styles__.forEach(function (module) {\n' +
309
+ 'for (var name in module) {\n' +
310
+ '__vue_options__.style[name] = module[name]\n' +
311
+ '}\n' +
312
+ '})\n'
288
313
289
314
if ( ! query . inject ) {
290
315
output += exports
291
316
// hot reload
292
- if (
293
- ! isServer &&
294
- ! isProduction &&
295
- ( parts . script || parts . template )
296
- ) {
297
- output +=
298
- '\n/* hot reload */\n' +
299
- 'if (module.hot) {(function () {\n' +
300
- ' var hotAPI = require("' + hotReloadAPIPath + '")\n' +
301
- ' hotAPI.install(require("vue"), false)\n' +
302
- ' if (!hotAPI.compatible) return\n' +
303
- ' module.hot.accept()\n' +
304
- ' if (!module.hot.data) {\n' +
305
- // initial insert
306
- ' hotAPI.createRecord("' + moduleId + '", __vue_options__)\n' +
307
- ' } else {\n' +
308
- // update
309
- ' hotAPI.reload("' + moduleId + '", __vue_options__)\n' +
310
- ' }\n' +
311
- '})()}\n'
312
- }
317
+ // if (
318
+ // !isServer &&
319
+ // !isProduction &&
320
+ // (parts.script || parts.template)
321
+ // ) {
322
+ // output +=
323
+ // '\n/* hot reload */\n' +
324
+ // 'if (module.hot) {(function () {\n' +
325
+ // ' var hotAPI = require("' + hotReloadAPIPath + '")\n' +
326
+ // ' hotAPI.install(require("vue"), false)\n' +
327
+ // ' if (!hotAPI.compatible) return\n' +
328
+ // ' module.hot.accept()\n' +
329
+ // ' if (!module.hot.data) {\n' +
330
+ // // initial insert
331
+ // ' hotAPI.createRecord("' + moduleId + '", __vue_options__)\n' +
332
+ // ' } else {\n' +
333
+ // // update
334
+ // ' hotAPI.reload("' + moduleId + '", __vue_options__)\n' +
335
+ // ' }\n' +
336
+ // '})() }\n'
337
+ // }
313
338
// check functional
314
- if ( ! isProduction ) {
315
- output +=
316
- 'if (__vue_options__.functional) {console.error("' +
317
- '[vue-loader] ' + fileName + ': functional components are not ' +
318
- 'supported and should be defined in plain js files using render ' +
319
- 'functions.' +
320
- '")}\n'
321
- }
339
+ // if (!isProduction) {
340
+ // output +=
341
+ // 'if (__vue_options__.functional) {console.error("' +
342
+ // '[vue-loader] ' + fileName + ': functional components are not ' +
343
+ // 'supported and should be defined in plain js files using render ' +
344
+ // 'functions.' +
345
+ // '")}\n'
346
+ // }
322
347
// final export
323
348
if ( options . esModule ) {
324
349
output += '\nexports.__esModule = true;\nexports["default"] = __vue_exports__\n'
@@ -336,6 +361,11 @@ module.exports = function (content) {
336
361
'}'
337
362
}
338
363
364
+ if ( params . entry ) {
365
+ output += 'module.exports.el = \'body\'\n' +
366
+ 'new Vue(module.exports)\n'
367
+ }
368
+
339
369
// done
340
370
return output
341
371
}
0 commit comments