Skip to content

Commit 91abd72

Browse files
xsbchenyyx990803
authored andcommitted
support webpack2 and extract-text-webpack-plugin 2 (vuejs#626)
1 parent 72aa554 commit 91abd72

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/loader.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,25 @@ module.exports = function (content) {
106106
})
107107
}
108108

109+
// stringify an Array of loader objects
110+
function stringifyLoaders (loaders) {
111+
return loaders.map(function (obj) {
112+
return obj && typeof obj === 'object' && typeof obj.loader === 'string'
113+
? obj.loader + (obj.options ? '?' + JSON.stringify(obj.options) : '')
114+
: obj
115+
}).join('!')
116+
}
117+
109118
function getLoaderString (type, part, index, scoped) {
110119
var lang = part.lang || defaultLang[type]
111120
var loader = loaders[lang]
112121
var rewriter = getRewriter(type, scoped)
113122
var injectString = (type === 'script' && query.inject) ? 'inject!' : ''
114123
if (loader !== undefined) {
124+
if (Array.isArray(loader)) {
125+
loader = stringifyLoaders(loader)
126+
}
127+
115128
if (type === 'style') {
116129
loader = addCssModulesToLoader(loader, part, index)
117130
}

test/test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ describe('vue-loader', function () {
221221
})
222222
})
223223

224+
it('extract CSS by extract-text-webpack-plugin 2', function (done) {
225+
webpack(Object.assign({}, globalConfig, {
226+
entry: './test/fixtures/extract-css.vue',
227+
vue: {
228+
loaders: {
229+
css: [{ loader: ExtractTextPlugin.loader({ remove: true }) }, { loader: 'css-loader' }],
230+
stylus: [{ loader: ExtractTextPlugin.loader({ remove: true }) }, { loader: 'css-loader?sourceMap' }, { loader: 'stylus-loader' }]
231+
}
232+
},
233+
plugins: [
234+
new ExtractTextPlugin('test.output2.css')
235+
]
236+
}), function (err, stats) {
237+
expect(stats.compilation.errors).to.be.empty
238+
getFile('test.output2.css', function (data) {
239+
expect(data).to.contain('h1 {\n color: #f00;\n}\n\n\n\n\n\n\nh2 {\n color: green;\n}')
240+
done()
241+
})
242+
})
243+
})
244+
224245
it('dependency injection', function (done) {
225246
test({
226247
entry: './test/fixtures/inject.js'

0 commit comments

Comments
 (0)