Skip to content

Commit 2035543

Browse files
authored
fix(build): demo-lib.html Vue 3 compatibility (#6366)
1 parent 212d721 commit 2035543

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8">
33
<title><%- htmlWebpackPlugin.options.libName %> demo</title>
4-
<script src="https://unpkg.com/vue"></script>
4+
<script src="//unpkg.com/vue@<%- htmlWebpackPlugin.options.vueMajor %>"></script>
55
<script src="./<%- htmlWebpackPlugin.options.assetsFileName %>.umd.js"></script>
66
<% if (htmlWebpackPlugin.options.cssExtract) { %>
77
<link rel="stylesheet" href="./<%- htmlWebpackPlugin.options.assetsFileName %>.css">
@@ -12,9 +12,17 @@
1212
</div>
1313

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

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

+3
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)