Skip to content

Commit b2295fc

Browse files
committed
chore: merge remote-tracking branch 'upstream/dev' into plugin-order
2 parents e04831f + e661a92 commit b2295fc

40 files changed

+971
-550
lines changed

docs/guide/browser-compatibility.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ For a Hello World app, the modern bundle is already 16% smaller. In production,
7171
::: tip
7272
`<script type="module">` is loaded [with CORS always enabled](https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors). This means your server must return valid CORS headers such as `Access-Control-Allow-Origin: *`. If you want to fetch the scripts with credentials, set the [crossorigin](../config/#crossorigin) option to `use-credentials`.
7373

74-
Also, modern mode uses an inline script to avoid Safari 10 loading both bundles, so if you are using a strict CSP, you will need to explicitly allow the inline script with:
75-
76-
```
77-
Content-Security-Policy: script-src 'self' 'sha256-4RS22DYeB7U14dra4KcQYxmwt5HkOInieXK1NUMBmQI='
78-
```
79-
:::
80-
8174
::: tip Detecting the Current Mode in Config
8275
Sometimes you may need to change the webpack config only for the legacy build, or only for the modern build.
8376

docs/guide/cli-service.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Options:
7575
--mode specify env mode (default: production)
7676
--dest specify output directory (default: dist)
7777
--modern build app targeting modern browsers with auto fallback
78-
--no-unsafe-inline build app without introducing inline scripts
7978
--target app | lib | wc | wc-async (default: app)
8079
--formats list of output formats for library builds (default: commonjs,umd,umd-min)
8180
--inline-vue include the Vue module in the final bundle of library or web component target

docs/zh/guide/browser-compatibility.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ Vue CLI 会产生两个应用的版本:一个现代版的包,面向支持 [E
7171
::: tip 提示
7272
`<script type="module">` [需要配合始终开启的 CORS 进行加载](https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors)。这意味着你的服务器必须返回诸如 `Access-Control-Allow-Origin: *` 的有效的 CORS 头。如果你想要通过认证来获取脚本,可使将 [crossorigin](../config/#crossorigin) 选项设置为 `use-credentials`。
7373

74-
同时,现代浏览器使用一段内联脚本来避免 Safari 10 重复加载脚本包,所以如果你在使用一套严格的 CSP,你需要这样显性地允许内联脚本:
75-
76-
```
77-
Content-Security-Policy: script-src 'self' 'sha256-4RS22DYeB7U14dra4KcQYxmwt5HkOInieXK1NUMBmQI='
78-
```
79-
:::
80-
8174
[autoprefixer]: https://github.com/postcss/autoprefixer
8275
[babel-preset-env]: https://new.babeljs.io/docs/en/next/babel-preset-env.html
8376
[babel-preset-app]: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"packages/vue-cli-version-marker"
77
],
88
"scripts": {
9-
"test": "node scripts/test.js",
9+
"test": "node --experimental-vm-modules scripts/test.js",
1010
"pretest": "yarn clean",
1111
"lint": "eslint --fix packages/**/*.js packages/**/bin/*",
1212
"lint-without-fix": "eslint packages/**/*.js packages/**/bin/*",

packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const babel = require('@babel/core')
33
const preset = require('../index')
44
const defaultOptions = {
55
babelrc: false,
6-
presets: [preset],
6+
presets: [[preset, { targets: { ie: 9 } }]],
77
filename: 'test-entry-file.js'
88
}
99

@@ -161,6 +161,7 @@ test('disable absoluteRuntime', () => {
161161
`.trim(), {
162162
babelrc: false,
163163
presets: [[preset, {
164+
targets: { ie: 9 },
164165
absoluteRuntime: false
165166
}]],
166167
filename: 'test-entry-file.js'
@@ -183,6 +184,7 @@ test('should inject polyfills / helpers using "require" statements for a umd mod
183184
`.trim(), {
184185
babelrc: false,
185186
presets: [[preset, {
187+
targets: { ie: 9 },
186188
absoluteRuntime: false
187189
}]],
188190
filename: 'test-entry-file.js'
@@ -200,6 +202,7 @@ test('should inject polyfills / helpers using "import" statements for an es modu
200202
`.trim(), {
201203
babelrc: false,
202204
presets: [[preset, {
205+
targets: { ie: 9 },
203206
absoluteRuntime: false
204207
}]],
205208
filename: 'test-entry-file.js'

packages/@vue/babel-preset-app/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const {
1919
isRequired
2020
} = require('@babel/helper-compilation-targets')
2121

22+
// We'll no longer need this logic in Babel 8 as it's the default behavior
23+
// See discussions at:
24+
// https://github.com/babel/rfcs/pull/2#issuecomment-714785228
25+
// https://github.com/babel/babel/pull/12189
2226
function getIntersectionTargets (targets, constraintTargets) {
2327
const intersection = Object.keys(constraintTargets).reduce(
2428
(results, browser) => {
@@ -43,14 +47,14 @@ function getIntersectionTargets (targets, constraintTargets) {
4347
return intersection
4448
}
4549

46-
function getModernTargets (targets) {
47-
const allModernTargets = getTargets(
50+
function getModuleTargets (targets) {
51+
const allModuleTargets = getTargets(
4852
{ esmodules: true },
4953
{ ignoreBrowserslistConfig: true }
5054
)
5155

5256
// use the intersection of modern mode browsers and user defined targets config
53-
return getIntersectionTargets(targets, allModernTargets)
57+
return getIntersectionTargets(targets, allModuleTargets)
5458
}
5559

5660
function getWCTargets (targets) {
@@ -177,7 +181,7 @@ module.exports = (context, options = {}) => {
177181
targets = getWCTargets(targets)
178182
} else if (process.env.VUE_CLI_MODERN_BUILD) {
179183
// targeting browsers that at least support <script type="module">
180-
targets = getModernTargets(targets)
184+
targets = getModuleTargets(targets)
181185
}
182186

183187
// included-by-default polyfills. These are common polyfills that 3rd party

packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ async function readVendorFile () {
1313
return project.read(`dist/js/${filename}`)
1414
}
1515

16+
async function readLegacyVendorFile () {
17+
const files = await fs.readdir(path.join(project.dir, 'dist/js'))
18+
const filename = files.find(f => /chunk-vendors-legacy\.[^.]+\.js$/.test(f))
19+
return project.read(`dist/js/${filename}`)
20+
}
21+
1622
beforeAll(async () => {
1723
project = await create('babel-transpile-deps', defaultPreset)
1824

@@ -39,6 +45,8 @@ beforeAll(async () => {
3945
let $packageJson = await project.read('package.json')
4046

4147
$packageJson = JSON.parse($packageJson)
48+
$packageJson.browserslist.push('ie 11') // to ensure arrow function transformation is enabled
49+
$packageJson.browserslist.push('safari 11') // to ensure optional chaining transformation is enabled
4250
$packageJson.dependencies['external-dep'] = '1.0.0'
4351
$packageJson.dependencies['@scope/external-dep'] = '1.0.0'
4452
$packageJson = JSON.stringify($packageJson)
@@ -70,7 +78,7 @@ afterAll(async () => {
7078

7179
test('dep from node_modules should not been transpiled by default', async () => {
7280
await project.run('vue-cli-service build')
73-
expect(await readVendorFile()).toMatch('() => "__TEST__"')
81+
expect(await readLegacyVendorFile()).toMatch('() => "__TEST__"')
7482
})
7583

7684
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
7987
`module.exports = { transpileDependencies: ['external-dep', '@scope/external-dep'] }`
8088
)
8189
await project.run('vue-cli-service build')
82-
expect(await readVendorFile()).toMatch('return "__TEST__"')
90+
expect(await readLegacyVendorFile()).toMatch('return "__TEST__"')
8391

84-
expect(await readVendorFile()).toMatch('return "__SCOPE_TEST__"')
92+
expect(await readLegacyVendorFile()).toMatch('return "__SCOPE_TEST__"')
8593
})
8694

8795
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
9098
`module.exports = { transpileDependencies: true }`
9199
)
92100
await project.run('vue-cli-service build')
93-
expect(await readVendorFile()).toMatch('return "__TEST__"')
101+
expect(await readLegacyVendorFile()).toMatch('return "__TEST__"')
94102

95-
expect(await readVendorFile()).toMatch('return "__SCOPE_TEST__"')
103+
expect(await readLegacyVendorFile()).toMatch('return "__SCOPE_TEST__"')
96104
})
97105

98106
// https://github.com/vuejs/vue-cli/issues/3057
@@ -104,6 +112,24 @@ test('only transpile package with same name specified in transpileDependencies',
104112
try {
105113
await project.run('vue-cli-service build')
106114
} catch (e) {}
107-
expect(await readVendorFile()).toMatch('() => "__TEST__"')
108-
expect(await readVendorFile()).toMatch('() => "__SCOPE_TEST__"')
115+
expect(await readLegacyVendorFile()).toMatch('() => "__TEST__"')
116+
expect(await readLegacyVendorFile()).toMatch('() => "__SCOPE_TEST__"')
117+
})
118+
119+
test('when transpileDependencies is on, the module build should also include transpiled code (with a different target)', async () => {
120+
await project.write(
121+
'vue.config.js',
122+
`module.exports = { transpileDependencies: true }`
123+
)
124+
await project.write(
125+
'node_modules/external-dep/index.js',
126+
`const test = (x) => x?.y?.z;\nexport default test`
127+
)
128+
129+
await project.run('vue-cli-service build')
130+
const file = await readVendorFile()
131+
// module build won't need arrow function transformation
132+
expect(file).toMatch('() => "__SCOPE_TEST__"')
133+
// but still needs optional chaining transformation
134+
expect(file).not.toMatch('x?.y?.z')
109135
})

packages/@vue/cli-plugin-typescript/__tests__/tsPluginBabel.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Service = require('@vue/cli-service/lib/Service')
44
const create = require('@vue/cli-test-utils/createTestProject')
55
const { assertServe, assertBuild } = require('./tsPlugin.helper')
66

7-
test('using correct loader', () => {
7+
test('using correct loader', async () => {
88
const service = new Service('/', {
99
pkg: {},
1010
plugins: [
@@ -13,7 +13,7 @@ test('using correct loader', () => {
1313
]
1414
})
1515

16-
service.init()
16+
await service.init()
1717
const config = service.resolveWebpackConfig()
1818
// eslint-disable-next-line no-shadow
1919
const rule = config.module.rules.find(rule => rule.test.test('foo.ts'))

packages/@vue/cli-plugin-unit-jest/presets/default/jest-preset.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
let vueJest = null
2+
try {
3+
vueJest = require.resolve('vue-jest')
4+
} catch (e) {
5+
throw new Error('Cannot resolve "vue-jest" module. Please make sure you have installed "vue-jest" as a dev dependency.')
6+
}
7+
18
module.exports = {
29
moduleFileExtensions: [
310
'js',
@@ -8,7 +15,7 @@ module.exports = {
815
],
916
transform: {
1017
// process *.vue files with vue-jest
11-
'^.+\\.vue$': require.resolve('vue-jest'),
18+
'^.+\\.vue$': vueJest,
1219
'.+\\.(css|styl|less|sass|scss|jpg|jpeg|png|svg|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
1320
require.resolve('jest-transform-stub'),
1421
'^.+\\.jsx?$': require.resolve('babel-jest')
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
const deepmerge = require('deepmerge')
22
const defaultPreset = require('../default/jest-preset')
33

4+
let tsJest = null
5+
try {
6+
tsJest = require.resolve('ts-jest')
7+
} catch (e) {
8+
throw new Error('Cannot resolve "ts-jest" module. Typescript preset requires "ts-jest" to be installed.')
9+
}
10+
411
module.exports = deepmerge(
512
defaultPreset,
613
{
714
moduleFileExtensions: ['ts', 'tsx'],
815
transform: {
9-
'^.+\\.tsx?$': require.resolve('ts-jest')
16+
'^.+\\.tsx?$': tsJest
1017
}
1118
}
1219
)

packages/@vue/cli-plugin-webpack-4/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ module.exports = (api, rootOptions) => {
134134
})
135135
)
136136

137+
if (shouldExtract) {
138+
const CssMinimizerPluginV1 = require('css-minimizer-webpack-plugin')
139+
config.optimization.minimizer('css').init(
140+
(Plugin, [cssMinimizerOptions]) =>
141+
new CssMinimizerPluginV1({
142+
sourceMap: rootOptions.productionSourceMap,
143+
...cssMinimizerOptions
144+
})
145+
)
146+
}
147+
137148
// DeterministicModuleIdsPlugin is only available in webpack 5
138149
// (and enabled by default in production mode).
139150

packages/@vue/cli-plugin-webpack-4/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependencies": {
2626
"@vue/cli-shared-utils": "^5.0.0-alpha.8",
2727
"copy-webpack-plugin": "^6.4.1",
28+
"css-minimizer-webpack-plugin": "^1.2.0",
2829
"hash-sum": "^2.0.0",
2930
"html-webpack-plugin": "^4.5.1",
3031
"module-alias": "^2.2.2",

0 commit comments

Comments
 (0)