File tree Expand file tree Collapse file tree 2 files changed +40
-7
lines changed
Filter options
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) {
288
288
}
289
289
290
290
function getCSSExtractLoader ( lang ) {
291
- var extract
291
+ var extractor
292
292
var op = options . extractCSS
293
293
// extractCSS option is an instance of ExtractTextPlugin
294
294
if ( typeof op . extract === 'function' ) {
295
- extract = op . extract
295
+ extractor = op
296
296
} else {
297
- var plugin = tryRequire ( 'extract-text-webpack-plugin' )
298
- if ( ! plugin ) {
297
+ extractor = tryRequire ( 'extract-text-webpack-plugin' )
298
+ if ( ! extractor ) {
299
299
throw new Error (
300
300
'[vue-loader] extractCSS: true requires extract-text-webpack-plugin ' +
301
301
'as a peer dependency.'
302
302
)
303
- } else {
304
- extract = plugin . extract
305
303
}
306
304
}
307
305
var langLoader = lang
308
306
? ensureBang ( ensureLoader ( lang ) )
309
307
: ''
310
- return extract ( {
308
+ return extractor . extract ( {
311
309
use : 'css-loader' + cssLoaderOptions + '!' + langLoader ,
312
310
fallback : 'vue-style-loader'
313
311
} )
Original file line number Diff line number Diff line change @@ -293,6 +293,41 @@ describe('vue-loader', function () {
293
293
} )
294
294
} )
295
295
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
+
296
331
it ( 'dependency injection' , done => {
297
332
test ( {
298
333
entry : './test/fixtures/inject.js'
You can’t perform that action at this time.
0 commit comments