File tree Expand file tree Collapse file tree 2 files changed +40
-7
lines changed Expand file tree Collapse file tree 2 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -288,26 +288,24 @@ module.exports = function (content) {
288288 }
289289
290290 function getCSSExtractLoader ( lang ) {
291- var extract
291+ var extractor
292292 var op = options . extractCSS
293293 // extractCSS option is an instance of ExtractTextPlugin
294294 if ( typeof op . extract === 'function' ) {
295- extract = op . extract
295+ extractor = op
296296 } else {
297- var plugin = tryRequire ( 'extract-text-webpack-plugin' )
298- if ( ! plugin ) {
297+ extractor = tryRequire ( 'extract-text-webpack-plugin' )
298+ if ( ! extractor ) {
299299 throw new Error (
300300 '[vue-loader] extractCSS: true requires extract-text-webpack-plugin ' +
301301 'as a peer dependency.'
302302 )
303- } else {
304- extract = plugin . extract
305303 }
306304 }
307305 var langLoader = lang
308306 ? ensureBang ( ensureLoader ( lang ) )
309307 : ''
310- return extract ( {
308+ return extractor . extract ( {
311309 use : 'css-loader' + cssLoaderOptions + '!' + langLoader ,
312310 fallback : 'vue-style-loader'
313311 } )
Original file line number Diff line number Diff line change @@ -293,6 +293,41 @@ describe('vue-loader', function () {
293293 } )
294294 } )
295295
296+ it ( 'extract CSS using option' , done => {
297+ bundle ( {
298+ entry : './test/fixtures/extract-css.vue' ,
299+ vue : {
300+ extractCSS : true
301+ } ,
302+ plugins : [
303+ new ExtractTextPlugin ( 'test.output.css' )
304+ ]
305+ } , ( code , warnings ) => {
306+ var css = mfs . readFileSync ( '/test.output.css' ) . toString ( )
307+ css = normalizeNewline ( css )
308+ expect ( css ) . to . contain ( 'h1 {\n color: #f00;\n}\n\nh2 {\n color: green;\n}' )
309+ done ( )
310+ } )
311+ } )
312+
313+ it ( 'extract CSS using option (passing plugin instance)' , done => {
314+ const plugin = new ExtractTextPlugin ( 'test.output.css' )
315+ bundle ( {
316+ entry : './test/fixtures/extract-css.vue' ,
317+ vue : {
318+ extractCSS : plugin
319+ } ,
320+ plugins : [
321+ plugin
322+ ]
323+ } , ( code , warnings ) => {
324+ var css = mfs . readFileSync ( '/test.output.css' ) . toString ( )
325+ css = normalizeNewline ( css )
326+ expect ( css ) . to . contain ( 'h1 {\n color: #f00;\n}\n\nh2 {\n color: green;\n}' )
327+ done ( )
328+ } )
329+ } )
330+
296331 it ( 'dependency injection' , done => {
297332 test ( {
298333 entry : './test/fixtures/inject.js'
You can’t perform that action at this time.
0 commit comments