Skip to content

Commit 8626739

Browse files
committed
fix: compat with html-webpack-plugin
fix #1213
1 parent 7c37a71 commit 8626739

File tree

6 files changed

+236
-12
lines changed

6 files changed

+236
-12
lines changed

Diff for: lib/loaders/pitch.js renamed to lib/loaders/pitcher.js

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ module.exports = code => code
1010
// and transform it into appropriate requests.
1111
module.exports.pitch = function (remainingRequest) {
1212
const query = qs.parse(this.resourceQuery.slice(1))
13-
14-
if (query.vue == null) {
15-
return
16-
}
17-
1813
const loaders = this.loaders.slice(1) // remove self
1914

2015
// loader.request contains both the resolved loader path and its options

Diff for: lib/plugin.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ module.exports = class VueLoaderPlugin {
8989
// inject global pitcher (responsible for injecting template compiler
9090
// loader & CSS post loader)
9191
rawRules.unshift({
92-
loader: require.resolve('./loaders/pitch')
92+
loader: require.resolve('./loaders/pitcher'),
93+
resourceQuery: query => {
94+
const parsed = qs.parse(query.slice(1))
95+
return parsed.vue != null
96+
}
9397
})
9498
}
9599
}

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint": "^4.19.0",
5050
"eslint-plugin-vue-libs": "^2.1.0",
5151
"file-loader": "^1.1.11",
52+
"html-webpack-plugin": "^3.1.0",
5253
"javascript-stringify": "^1.6.0",
5354
"jest": "^22.4.2",
5455
"jsdom": "^11.6.2",

Diff for: test/edgeCases.spec.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
const path = require('path')
2+
const normalizeNewline = require('normalize-newline')
3+
const HTMLPlugin = require('html-webpack-plugin')
4+
15
const {
6+
mfs,
27
bundle,
38
mockRender,
49
mockBundleAndRun
510
} = require('./utils')
611

7-
const normalizeNewline = require('normalize-newline')
8-
912
const assertComponent = ({ window, module }, done) => {
1013
const vnode = mockRender(module, {
1114
msg: 'hi'
@@ -128,3 +131,20 @@ test('should not duplicate css modules value imports', done => {
128131
done()
129132
})
130133
})
134+
135+
test('html-webpack-plugin', done => {
136+
bundle({
137+
entry: 'basic.vue',
138+
plugins: [
139+
new HTMLPlugin({
140+
inject: true,
141+
template: path.resolve(__dirname, 'fixtures/index.html'),
142+
filename: 'output.html'
143+
})
144+
]
145+
}, () => {
146+
const html = mfs.readFileSync('/output.html', 'utf-8')
147+
expect(html).toMatch('test.build.js')
148+
done()
149+
}, true)
150+
})

Diff for: test/fixtures/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)