Skip to content

Commit

Permalink
fix(build): demo-lib.html Vue 3 compatibility (#6366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeneser authored Mar 22, 2021
1 parent 212d721 commit 2035543
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/@vue/cli-service/lib/commands/build/demo-lib.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title><%- htmlWebpackPlugin.options.libName %> demo</title>
<script src="https://unpkg.com/vue"></script>
<script src="//unpkg.com/vue@<%- htmlWebpackPlugin.options.vueMajor %>"></script>
<script src="./<%- htmlWebpackPlugin.options.assetsFileName %>.umd.js"></script>
<% if (htmlWebpackPlugin.options.cssExtract) { %>
<link rel="stylesheet" href="./<%- htmlWebpackPlugin.options.assetsFileName %>.css">
Expand All @@ -12,9 +12,17 @@
</div>

<script>
<% if (htmlWebpackPlugin.options.vueMajor === 3) { %>
Vue.createApp({
components: {
demo: <%- htmlWebpackPlugin.options.libName %>
}
}).mount('#app')
<% } else { %>
new Vue({
components: {
demo: <%- htmlWebpackPlugin.options.libName %>
}
}).$mount('#app')
<% } %>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = (api, { entry, name, formats, filename, 'inline-vue': inlineVue
process.exit(1)
}

const vueMajor = require('../../util/getVueMajor')(api.getCwd())

const fullEntryPath = api.resolve(entry)

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

0 comments on commit 2035543

Please sign in to comment.