diff --git a/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js b/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js
index 1c5d6c25c5..21f3d349a0 100644
--- a/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js
+++ b/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js
@@ -13,6 +13,12 @@ async function readVendorFile () {
return project.read(`dist/js/${filename}`)
}
+async function readLegacyVendorFile () {
+ const files = await fs.readdir(path.join(project.dir, 'dist/js'))
+ const filename = files.find(f => /chunk-vendors-legacy\.[^.]+\.js$/.test(f))
+ return project.read(`dist/js/${filename}`)
+}
+
beforeAll(async () => {
project = await create('babel-transpile-deps', defaultPreset)
@@ -39,6 +45,8 @@ beforeAll(async () => {
let $packageJson = await project.read('package.json')
$packageJson = JSON.parse($packageJson)
+ $packageJson.browserslist.push('ie 11') // to ensure arrow function transformation is enabled
+ $packageJson.browserslist.push('safari 11') // to ensure optional chaining transformation is enabled
$packageJson.dependencies['external-dep'] = '1.0.0'
$packageJson.dependencies['@scope/external-dep'] = '1.0.0'
$packageJson = JSON.stringify($packageJson)
@@ -70,7 +78,7 @@ afterAll(async () => {
test('dep from node_modules should not been transpiled by default', async () => {
await project.run('vue-cli-service build')
- expect(await readVendorFile()).toMatch('() => "__TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('() => "__TEST__"')
})
test('dep from node_modules should been transpiled when matched by transpileDependencies', async () => {
@@ -79,9 +87,9 @@ test('dep from node_modules should been transpiled when matched by transpileDepe
`module.exports = { transpileDependencies: ['external-dep', '@scope/external-dep'] }`
)
await project.run('vue-cli-service build')
- expect(await readVendorFile()).toMatch('return "__TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('return "__TEST__"')
- expect(await readVendorFile()).toMatch('return "__SCOPE_TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('return "__SCOPE_TEST__"')
})
test('dep from node_modules should been transpiled when transpileDependencies is true', async () => {
@@ -90,9 +98,9 @@ test('dep from node_modules should been transpiled when transpileDependencies is
`module.exports = { transpileDependencies: true }`
)
await project.run('vue-cli-service build')
- expect(await readVendorFile()).toMatch('return "__TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('return "__TEST__"')
- expect(await readVendorFile()).toMatch('return "__SCOPE_TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('return "__SCOPE_TEST__"')
})
// https://github.com/vuejs/vue-cli/issues/3057
@@ -104,6 +112,24 @@ test('only transpile package with same name specified in transpileDependencies',
try {
await project.run('vue-cli-service build')
} catch (e) {}
- expect(await readVendorFile()).toMatch('() => "__TEST__"')
- expect(await readVendorFile()).toMatch('() => "__SCOPE_TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('() => "__TEST__"')
+ expect(await readLegacyVendorFile()).toMatch('() => "__SCOPE_TEST__"')
+})
+
+test('when transpileDependencies is on, the module build should also include transpiled code (with a different target)', async () => {
+ await project.write(
+ 'vue.config.js',
+ `module.exports = { transpileDependencies: true }`
+ )
+ await project.write(
+ 'node_modules/external-dep/index.js',
+ `const test = (x) => x?.y?.z;\nexport default test`
+ )
+
+ await project.run('vue-cli-service build')
+ const file = await readVendorFile()
+ // module build won't need arrow function transformation
+ expect(file).toMatch('() => "__SCOPE_TEST__"')
+ // but still needs optional chaining transformation
+ expect(file).not.toMatch('x?.y?.z')
})
diff --git a/packages/@vue/cli-service/__tests__/build.spec.js b/packages/@vue/cli-service/__tests__/build.spec.js
index c32e8bffa8..ce94962897 100644
--- a/packages/@vue/cli-service/__tests__/build.spec.js
+++ b/packages/@vue/cli-service/__tests__/build.spec.js
@@ -38,8 +38,8 @@ test('build', async () => {
// expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/)
// should inject scripts
- expect(index).toMatch(/`)
-
// Test crossorigin="use-credentials"
await project.write('vue.config.js', `module.exports = { crossorigin: 'use-credentials' }`)
- const { stdout: stdout2 } = await project.run('vue-cli-service build --modern')
+ const { stdout: stdout2 } = await project.run('vue-cli-service build')
expect(stdout2).toMatch('Build complete.')
const index2 = await project.read('dist/index.html')
// should use `)
+
+ // `--no-unsafe-inline` option
+ stdout = (await project.run('vue-cli-service build --no-unsafe-inline')).stdout
+ expect(stdout).toMatch('Build complete.')
// should output a separate safari-nomodule-fix bundle
const files = await fs.readdir(path.join(project.dir, 'dist/js'))
expect(files.some(f => /^safari-nomodule-fix\.js$/.test(f))).toBe(true)
-
// should contain no inline scripts in the output html
- const index = await project.read('dist/index.html')
+ index = await project.read('dist/index.html')
expect(index).not.toMatch(/[^>]\s*<\/script>/)
})
+test('--no-module', async () => {
+ const project = await create('no-module', defaultPreset)
+
+ const { stdout } = await project.run('vue-cli-service build --no-module')
+ expect(stdout).toMatch('Build complete.')
+
+ const index = await project.read('dist/index.html')
+ expect(index).not.toMatch('type="module"')
+
+ const files = await fs.readdir(path.join(project.dir, 'dist/js'))
+ expect(files.some(f => /-legacy.js/.test(f))).toBe(false)
+})
+
afterAll(async () => {
if (browser) {
await browser.close()
diff --git a/packages/@vue/cli-service/__tests__/multiPage.spec.js b/packages/@vue/cli-service/__tests__/multiPage.spec.js
index 441fe07537..b055a24f85 100644
--- a/packages/@vue/cli-service/__tests__/multiPage.spec.js
+++ b/packages/@vue/cli-service/__tests__/multiPage.spec.js
@@ -110,14 +110,14 @@ test('build w/ multi page', async () => {
const assertSharedAssets = file => {
// should split and preload vendor chunk
// expect(file).toMatch(/]*js\/chunk-vendors[^>]*\.js" rel="preload" as="script">/)
- expect(file).toMatch(/