Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d715da3

Browse filesBrowse files
committed
tests for extractCSS option
1 parent e56ef61 commit d715da3
Copy full SHA for d715da3

File tree

Expand file treeCollapse file tree

2 files changed

+40
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-7
lines changed

‎lib/loader.js

Copy file name to clipboardExpand all lines: lib/loader.js
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff 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
})

‎test/test.js

Copy file name to clipboardExpand all lines: test/test.js
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.