Skip to content

Commit 37f16cc

Browse files
jeneserhaoqunjiang
authored andcommitted
fix(build): demo-lib.html Vue 3 compatibility (#6366)
1 parent e9ac77c commit 37f16cc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/@vue/cli-service/lib/commands/build/demo-lib.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<meta charset="utf-8">
22
<title><%- htmlWebpackPlugin.options.libName %> demo</title>
3-
<script src="https://unpkg.com/vue"></script>
3+
<script src="//unpkg.com/vue@<%- htmlWebpackPlugin.options.vueMajor %>"></script>
44
<script src="./<%- htmlWebpackPlugin.options.assetsFileName %>.umd.js"></script>
55
<% if (htmlWebpackPlugin.options.cssExtract) { %>
66
<link rel="stylesheet" href="./<%- htmlWebpackPlugin.options.assetsFileName %>.css">
@@ -11,9 +11,17 @@
1111
</div>
1212

1313
<script>
14+
<% if (htmlWebpackPlugin.options.vueMajor === 3) { %>
15+
Vue.createApp({
16+
components: {
17+
demo: <%- htmlWebpackPlugin.options.libName %>
18+
}
19+
}).mount('#app')
20+
<% } else { %>
1421
new Vue({
1522
components: {
1623
demo: <%- htmlWebpackPlugin.options.libName %>
1724
}
1825
}).$mount('#app')
26+
<% } %>
1927
</script>

packages/@vue/cli-service/lib/commands/build/resolveLibConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module.exports = (api, { entry, name, formats, filename, 'inline-vue': inlineVue
99
process.exit(1)
1010
}
1111

12+
const vueMajor = require('../../util/getVueMajor')(api.getCwd())
13+
1214
const fullEntryPath = api.resolve(entry)
1315

1416
if (!fs.existsSync(fullEntryPath)) {
@@ -66,6 +68,7 @@ module.exports = (api, { entry, name, formats, filename, 'inline-vue': inlineVue
6668
inject: false,
6769
filename: 'demo.html',
6870
libName,
71+
vueMajor,
6972
assetsFileName: filename,
7073
cssExtract: config.plugins.has('extract-css')
7174
}])

0 commit comments

Comments
 (0)