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 812f24d

Browse filesBrowse files
committed
fix compat with extract css plugin (close vuejs#51)
1 parent a8e2975 commit 812f24d
Copy full SHA for 812f24d

File tree

Expand file treeCollapse file tree

5 files changed

+59
-4
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+59
-4
lines changed

‎lib/loader.js

Copy file name to clipboardExpand all lines: lib/loader.js
+24-3Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,23 @@ module.exports = function (content) {
6565
var lang = part.lang || defaultLang[type]
6666
var loader = loaders[lang]
6767
var rewriter = getRewriter(type, scoped)
68+
var cssRE = /\b(css!?)\b/
69+
var htmlRE = /\b((vue-)?html!?)\b/
6870
if (loader !== undefined) {
69-
// lang with default or pre-configured loader
70-
if (loader) loader += '!'
71-
return loader + rewriter
71+
// inject rewriter before css/html loader for
72+
// extractTextPlugin use cases
73+
if (cssRE.test(loader)) {
74+
loader = loader.replace(cssRE, function (m, $1) {
75+
return ensureBang($1) + rewriter
76+
})
77+
} else if (htmlRE.test(loader)) {
78+
loader = loader.replace(htmlRE, function (m, $1) {
79+
return ensureBang($1) + rewriter
80+
})
81+
} else {
82+
loader = ensureBang(loader) + rewriter
83+
}
84+
return ensureBang(loader)
7285
} else {
7386
// unknown lang, assume a loader for it is used
7487
switch (type) {
@@ -99,6 +112,14 @@ module.exports = function (content) {
99112
'&index=' + index + '!'
100113
}
101114

115+
function ensureBang (loader) {
116+
if (loader.charAt(loader.length - 1) !== '!') {
117+
return loader + '!'
118+
} else {
119+
return loader
120+
}
121+
}
122+
102123
var url = '!!' + parserPath + '!' + vueUrl
103124
this.loadModule(url, function (err, source) {
104125
if (err) return cb(err)

‎package.json

Copy file name to clipboardExpand all lines: package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"chai": "^3.0.0",
4646
"css-loader": "^0.21.0",
4747
"eslint": "^1.6.0",
48-
"vue-html-loader": "^1.0.0",
48+
"extract-text-webpack-plugin": "^0.8.2",
4949
"jade": "^1.11.0",
5050
"jsdom": "^6.5.1",
5151
"mkdirp": "^0.5.1",
@@ -56,6 +56,7 @@
5656
"style-loader": "^0.13.0",
5757
"stylus-loader": "^1.4.0",
5858
"template-html-loader": "^0.0.3",
59+
"vue-html-loader": "^1.0.0",
5960
"webpack": "^1.12.2"
6061
}
6162
}

‎test/fixtures/extract-css.js

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./extract-css.vue')

‎test/fixtures/extract-css.vue

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<style lang="stylus">
2+
h1
3+
color red
4+
</style>
5+
6+
<style>
7+
h2 {
8+
color: green;
9+
}
10+
</style>

‎test/test.js

Copy file name to clipboardExpand all lines: test/test.js
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var assign = require('object-assign')
77
var rimraf = require('rimraf')
88
var hash = require('hash-sum')
99
var SourceMapConsumer = require('source-map').SourceMapConsumer
10+
var ExtractTextPlugin = require("extract-text-webpack-plugin")
1011

1112
describe('vue-loader', function () {
1213

@@ -170,4 +171,25 @@ describe('vue-loader', function () {
170171
})
171172
})
172173

174+
it('extract CSS', function (done) {
175+
webpack(Object.assign({}, globalConfig, {
176+
entry: './test/fixtures/extract-css.js',
177+
vue: {
178+
loaders: {
179+
css: ExtractTextPlugin.extract('css'),
180+
stylus: ExtractTextPlugin.extract('css!stylus')
181+
}
182+
},
183+
plugins: [
184+
new ExtractTextPlugin('test.output.css')
185+
]
186+
}), function (err) {
187+
expect(err).to.be.null
188+
getFile('test.output.css', function (data) {
189+
expect(data).to.contain('h1 {\n color: #f00;\n}\nh2 {\n color: green;\n}')
190+
done()
191+
})
192+
})
193+
})
194+
173195
})

0 commit comments

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