-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix transpileDependencies by always using babel.config.js
- Loading branch information
Showing
3 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
jest.setTimeout(30000) | ||
|
||
const { defaultPreset } = require('@vue/cli/lib/options') | ||
const create = require('@vue/cli-test-utils/createTestProject') | ||
|
||
let project | ||
|
||
beforeAll(async () => { | ||
project = await create('babel-transpile-deps', defaultPreset) | ||
|
||
await project.write( | ||
'node_modules/external-dep/package.json', | ||
`{ "name": "external-dep", "version": "1.0.0", "main": "index.js" }` | ||
) | ||
|
||
await project.write( | ||
'node_modules/external-dep/index.js', | ||
`const test = () => "__TEST__";\nexport default test` | ||
) | ||
|
||
let $packageJson = await project.read('package.json') | ||
|
||
$packageJson = JSON.parse($packageJson) | ||
$packageJson.dependencies['external-dep'] = '1.0.0' | ||
$packageJson = JSON.stringify($packageJson) | ||
|
||
await project.write( | ||
'package.json', | ||
$packageJson | ||
) | ||
|
||
let $mainjs = await project.read('src/main.js') | ||
|
||
$mainjs = `import test from 'external-dep'\n${$mainjs}\nconsole.log(test())` | ||
|
||
await project.write( | ||
'src/main.js', | ||
$mainjs | ||
) | ||
}) | ||
|
||
test('dep from node_modules should not been transpiled', async () => { | ||
const { stdout } = await project.run('vue-cli-service build') | ||
|
||
let $vendorjs = stdout.match(/(js\/vendors~app\.[^.]+\.js)/)[1] | ||
|
||
$vendorjs = `dist/${$vendorjs}` | ||
$vendorjs = await project.read($vendorjs) | ||
|
||
expect($vendorjs).toMatch('() => "__TEST__"') | ||
}) | ||
|
||
test('dep from node_modules should been transpiled', async () => { | ||
await project.write( | ||
'vue.config.js', | ||
`module.exports = { transpileDependencies: ['external-dep'] }` | ||
) | ||
|
||
const { stdout } = await project.run('vue-cli-service build') | ||
|
||
let $vendorjs = stdout.match(/(js\/vendors~app\.[^.]+\.js)/)[1] | ||
|
||
$vendorjs = `dist/${$vendorjs}` | ||
$vendorjs = await project.read($vendorjs) | ||
|
||
expect($vendorjs).toMatch('return "__TEST__"') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters