@@ -7,21 +7,20 @@ var path = require('path')
77
88var defaultLang = {
99 template : 'html' ,
10- style : 'css' ,
10+ styles : 'css' ,
1111 script : 'js'
1212}
1313
14- var rewriterInjectRE = / \b ( ( c s s | ( v u e - ) ? h t m l ) ( - l o a d e r ) ? ( \? [ ^ ! ] + ) ? ) (?: ! | $ ) /
14+ var rewriterInjectRE = / \b ( c s s ( - l o a d e r ) ? ( \? [ ^ ! ] + ) ? ) (?: ! | $ ) /
1515var rewriters = {
16- template : require . resolve ( './template-rewriter' ) ,
17- style : require . resolve ( './style-rewriter' )
16+ styles : require . resolve ( './style-rewriter' )
1817}
1918
2019var templateLoader = require . resolve ( './template-loader' )
2120
2221module . exports = function ( content ) {
2322 var defaultLoaders = {
24- html : 'vue-html-loader' ,
23+ html : require . resolve ( './template-compiler' ) ,
2524 css : 'vue-style-loader!css-loader' ,
2625 js : 'babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false'
2726 }
@@ -106,8 +105,8 @@ module.exports = function (content) {
106105 // unknown lang, infer the loader to be used
107106 switch ( type ) {
108107 case 'template' :
109- return defaultLoaders . html + '!' + rewriter + templateLoader + '?raw&engine=' + lang + '!'
110- case 'style ' :
108+ return defaultLoaders . html + '!' + templateLoader + '?raw&engine=' + lang + '!'
109+ case 'styles ' :
111110 return defaultLoaders . css + '!' + rewriter + lang + '!'
112111 case 'script' :
113112 return injectString + lang + '!'
@@ -143,35 +142,25 @@ module.exports = function (content) {
143142
144143 var parts = parse ( content , fileName , this . sourceMap )
145144 var hasLocalStyles = false
146- var output = 'var __vue_script__, __vue_template__\n'
147-
148- // check if there are any template syntax errors
149- var templateWarnings = parts . template . length && parts . template [ 0 ] . warnings
150- if ( templateWarnings ) {
151- templateWarnings . forEach ( this . emitError )
152- }
153-
154- // add requires for src imports
155- parts . styleImports . forEach ( function ( impt ) {
156- if ( impt . scoped ) hasLocalStyles = true
157- output += getRequireForImport ( 'style' , impt , impt . scoped )
158- } )
145+ var output = ''
159146
160147 // add requires for styles
161- parts . style . forEach ( function ( style , i ) {
162- if ( style . scoped ) hasLocalStyles = true
163- output += getRequire ( 'style' , style , i , style . scoped )
148+ parts . styles . forEach ( function ( style , i ) {
149+ var scoped = style . scoped
150+ if ( scoped ) hasLocalStyles = true
151+ output += style . src
152+ ? getRequireForImport ( 'styles' , style . src , scoped )
153+ : getRequire ( 'styles' , style , i , scoped )
164154 } )
165155
166156 // add require for script
167- var script
168- if ( parts . script . length ) {
169- script = parts . script [ 0 ]
157+ var script = parts . script
158+ if ( script ) {
170159 output +=
171- '__vue_script__ = ' + (
160+ 'var __vue_script__ = ' + (
172161 script . src
173- ? getRequireForImport ( 'script' , script , 0 )
174- : getRequire ( 'script' , script , 0 )
162+ ? getRequireForImport ( 'script' , script )
163+ : getRequire ( 'script' , script )
175164 )
176165 // check and warn named exports
177166 if ( ! this . minimize ) {
@@ -187,68 +176,63 @@ module.exports = function (content) {
187176 }
188177 }
189178
179+ // plain require() compatibility
180+ var exports = 'if (__exports__.__esModule) __exports__ = __exports__.default\n'
181+
190182 // add require for template
191- var template
192- if ( parts . template . length ) {
193- template = parts . template [ 0 ]
194- output += '__vue_template__ = ' + (
195- template . src
196- ? getRequireForImport ( 'template' , template , hasLocalStyles )
197- : getRequire ( 'template' , template , 0 , hasLocalStyles )
198- )
183+ var template = parts . template
184+ if ( template ) {
185+ output += 'var __vue_template__ = ' + (
186+ template . src
187+ ? getRequireForImport ( 'template' , template , hasLocalStyles )
188+ : getRequire ( 'template' , template , null , hasLocalStyles )
189+ )
190+ // attach render functions to exported options
191+ exports +=
192+ 'var __vue_options__ = (typeof __exports__ === "function" ' +
193+ '? (__exports__.options || (__exports__.options = {})) ' +
194+ ': __exports__)\n' +
195+ '__vue_options__.render = __vue_template__.render\n' +
196+ '__vue_options__.staticRenderFns = __vue_template__.staticRenderFns\n'
199197 }
200198
201199 if ( ! query . inject ) {
202- // attach template
203200 output +=
204- 'module.exports = __vue_script__ || {}\n' +
205- 'if (module.exports.__esModule) module.exports = module.exports.default\n' +
206- 'if (__vue_template__) {\n' +
207- '(typeof module.exports === "function" ' +
208- '? (module.exports.options || (module.exports.options = {})) ' +
209- ': module.exports).template = __vue_template__\n' +
210- '}\n'
201+ 'var __exports__ = __vue_script__ || {}\n' +
202+ exports +
203+ 'module.exports = __exports__'
211204 // hot reload
212- if (
213- ! this . minimize &&
214- process . env . NODE_ENV !== 'production' &&
215- ( parts . script . length || parts . template . length )
216- ) {
217- output +=
218- 'if (module.hot) {(function () {' +
219- ' module.hot.accept()\n' +
220- ' var hotAPI = require("vue-hot-reload-api")\n' +
221- ' hotAPI.install(require("vue"), false)\n' +
222- ' if (!hotAPI.compatible) return\n' +
223- ' var id = ' + loaderUtils . stringifyRequest ( loaderContext , filePath ) + '\n' +
224- ' if (!module.hot.data) {\n' +
225- // initial insert
226- ' hotAPI.createRecord(id, module.exports)\n' +
227- ' } else {\n' +
228- // update
229- ' hotAPI.update(id, module.exports, __vue_template__)\n' +
230- ' }\n' +
231- '})()}'
232- }
205+ // if (
206+ // !this.minimize &&
207+ // process.env.NODE_ENV !== 'production' &&
208+ // (parts.script.length || parts.template.length)
209+ // ) {
210+ // output +=
211+ // 'if (module.hot) {(function () {' +
212+ // ' module.hot.accept()\n' +
213+ // ' var hotAPI = require("vue-hot-reload-api")\n' +
214+ // ' hotAPI.install(require("vue"), false)\n' +
215+ // ' if (!hotAPI.compatible) return\n' +
216+ // ' var id = ' + loaderUtils.stringifyRequest(loaderContext, filePath) + '\n' +
217+ // ' if (!module.hot.data) {\n' +
218+ // // initial insert
219+ // ' hotAPI.createRecord(id, module.exports)\n' +
220+ // ' } else {\n' +
221+ // // update
222+ // ' hotAPI.update(id, module.exports, __vue_template__)\n' +
223+ // ' }\n' +
224+ // '})() }'
225+ // }
233226 } else {
234227 output +=
235228 'module.exports = function (injections) {\n' +
236- ' var mod = __vue_script__\n' +
229+ ' var __exports__ = __vue_script__\n' +
237230 ' ? __vue_script__(injections)\n' +
238- ' : {}\n' +
239- ' if (mod.__esModule) mod = mod.default\n' +
240- ' if (__vue_template__) { (typeof mod === "function" ? mod.options : mod).template = __vue_template__ }\n' +
241- ' return mod\n' +
231+ ' : {}\n' + exports +
232+ ' return __exports__\n' +
242233 '}'
243234 }
244235
245236 // done
246237 return output
247238}
248-
249- module . exports . withLoaders = function ( ) {
250- throw new Error (
251- 'vue.withLoaders has been deprecated in vue-loader 6.0. ' +
252- 'Add a "vue" section to the webpack config instead.'
253- )
254- }
0 commit comments