Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/@vue/cli-service/__tests__/buildWc.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jest.setTimeout(30000)

const fs = require('fs-extra')
const path = require('path')
const portfinder = require('portfinder')
const createServer = require('@vue/cli-test-utils/createServer')
Expand All @@ -16,8 +17,9 @@ test('build as wc', async () => {
expect(stdout).toMatch('Build complete.')

expect(project.has('dist/demo.html')).toBe(true)
expect(project.has('dist/build-wc.js')).toBe(true)
expect(project.has('dist/build-wc.min.js')).toBe(true)
const files = await fs.readdir(path.resolve(project.dir, 'dist'))
expect(files.filter(f => f.match(/build-wc\.\w{8}\.js$/)).length).toBe(1)
expect(files.filter(f => f.match(/build-wc\.\w{8}\.min\.js$/)).length).toBe(1)

const port = await portfinder.getPortPromise()
server = createServer({ root: path.join(project.dir, 'dist') })
Expand Down Expand Up @@ -61,8 +63,9 @@ test('build as single wc', async () => {
expect(stdout).toMatch('Build complete.')

expect(project.has('dist/demo.html')).toBe(true)
expect(project.has('dist/single-wc.js')).toBe(true)
expect(project.has('dist/single-wc.min.js')).toBe(true)
const files = await fs.readdir(path.resolve(project.dir, 'dist'))
expect(files.filter(f => f.match(/single-wc\.\w{8}\.js$/)).length).toBe(1)
expect(files.filter(f => f.match(/single-wc\.\w{8}\.min\.js$/)).length).toBe(1)

const port = await portfinder.getPortPromise()
server = createServer({ root: path.join(project.dir, 'dist') })
Expand Down Expand Up @@ -122,8 +125,9 @@ test('build as wc with --inline-vue', async () => {
expect(stdout).toMatch('Build complete.')

expect(project.has('dist/demo.html')).toBe(true)
expect(project.has('dist/single-wc.js')).toBe(true)
expect(project.has('dist/single-wc.min.js')).toBe(true)
const files = await fs.readdir(path.resolve(project.dir, 'dist'))
expect(files.filter(f => f.match(/single-wc\.\w{8}\.js$/)).length).toBe(1)
expect(files.filter(f => f.match(/single-wc\.\w{8}\.min\.js$/)).length).toBe(1)

const port = await portfinder.getPortPromise()
server = createServer({ root: path.join(project.dir, 'dist') })
Expand Down
10 changes: 5 additions & 5 deletions packages/@vue/cli-service/__tests__/buildWcAsync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ test('build as wc in async mode', async () => {
expect(stdout).toMatch('Build complete.')

expect(project.has('dist/demo.html')).toBe(true)
expect(project.has('dist/build-wc-async.js')).toBe(true)
expect(project.has('dist/build-wc-async.min.js')).toBe(true)
const files = await fs.readdir(path.resolve(project.dir, 'dist'))
expect(files.filter(f => f.match(/build-wc-async\.\w{8}\.js$/)).length).toBe(1)
expect(files.filter(f => f.match(/build-wc-async\.\w{8}\.min\.js$/)).length).toBe(1)

// code-split chunks
const files = await fs.readdir(path.resolve(project.dir, 'dist'))
const asyncOutputs = files.filter(f => f.match(/build-wc-async\.\d+\.js/))
const minifiedAsycnOutputs = files.filter(f => f.match(/build-wc-async\.\d+\.min\.js/))
const asyncOutputs = files.filter(f => f.match(/build-wc-async\.\d+\.\w{8}\.js/))
const minifiedAsycnOutputs = files.filter(f => f.match(/build-wc-async\.\d+\.\w{8}\.min\.js/))
expect(asyncOutputs.length).toBe(2)
expect(minifiedAsycnOutputs.length).toBe(2)

Expand Down
5 changes: 3 additions & 2 deletions packages/@vue/cli-service/lib/commands/build/demo-wc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<meta charset="utf-8">
<title><%- htmlWebpackPlugin.options.libName %> demo</title>
<script src="https://unpkg.com/vue"></script>
<script src="./<%- htmlWebpackPlugin.options.libName %>.js"></script>

<% for (var chunk in htmlWebpackPlugin.files.js) { %>
<script src="<%= htmlWebpackPlugin.files.js[chunk]%>"></script>
<% } %>
<% for (const comp of htmlWebpackPlugin.options.components) { %>
<<%= comp %>></<%= comp %>>
<% } %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const { resolveEntry, fileToComponentName } = require('./resolveWcEntry')

module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }, { filenameHashing }) => {
// Disable CSS extraction and turn on CSS shadow mode for vue-style-loader
process.env.VUE_CLI_CSS_SHADOW_MODE = true

Expand Down Expand Up @@ -115,14 +115,14 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
{ ...(inlineVue || { vue: 'Vue' }) }
].filter(Boolean)

const entryName = `${libName}${minify ? `.min` : ``}`
const entryName = `${libName}${filenameHashing ? '.[chunkhash:8]' : ''}${minify ? `.min` : ``}`
rawConfig.entry = {
[entryName]: dynamicEntry.filePath
}

Object.assign(rawConfig.output, {
filename: `${entryName}.js`,
chunkFilename: `${libName}.[name]${minify ? `.min` : ``}.js`,
chunkFilename: `${libName}.[name]${filenameHashing ? '.[chunkhash:8]' : ''}${minify ? `.min` : ``}.js`,
// use dynamic publicPath so this can be deployed anywhere
// the actual path will be determined at runtime by checking
// document.currentScript.src.
Expand Down