Skip to content

Commit 0aa8a55

Browse files
authored
feat!: always inject safari-nomodule-fix as an external script; drop --no-unsafe-inline flag (#6422)
1 parent 791fa28 commit 0aa8a55

File tree

6 files changed

+10
-34
lines changed

6 files changed

+10
-34
lines changed

docs/guide/browser-compatibility.md

-7
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

-1
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

-7
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

packages/@vue/cli-service/__tests__/modernMode.spec.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,14 @@ test('should inject nomodule-fix script when Safari 10 support is required', asy
100100
pkg.browserslist.push('safari > 10')
101101
await project.write('package.json', JSON.stringify(pkg, null, 2))
102102

103-
let { stdout } = await project.run('vue-cli-service build')
104-
let index = await project.read('dist/index.html')
105-
// should inject Safari 10 nomodule fix as an inline script
106-
const { safariFix } = require('../lib/webpack/SafariNomoduleFixPlugin')
107-
expect(index).toMatch(`<script>${safariFix}</script>`)
108-
109-
// `--no-unsafe-inline` option
110-
stdout = (await project.run('vue-cli-service build --no-unsafe-inline')).stdout
103+
const { stdout } = await project.run('vue-cli-service build')
111104
expect(stdout).toMatch('Build complete.')
105+
112106
// should output a separate safari-nomodule-fix bundle
113107
const files = await fs.readdir(path.join(project.dir, 'dist/js'))
114108
expect(files.some(f => /^safari-nomodule-fix\.js$/.test(f))).toBe(true)
109+
const index = await project.read('dist/index.html')
115110
// should contain no inline scripts in the output html
116-
index = await project.read('dist/index.html')
117111
expect(index).not.toMatch(/[^>]\s*<\/script>/)
118112
})
119113

packages/@vue/cli-service/lib/commands/build/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ const defaults = {
22
clean: true,
33
target: 'app',
44
module: true,
5-
formats: 'commonjs,umd,umd-min',
6-
'unsafe-inline': true
5+
formats: 'commonjs,umd,umd-min'
76
}
87

98
const buildModes = {
@@ -28,7 +27,6 @@ module.exports = (api, options) => {
2827
'--mode': `specify env mode (default: production)`,
2928
'--dest': `specify output directory (default: ${options.outputDir})`,
3029
'--no-module': `build app without generating <script type="module"> chunks for modern browsers`,
31-
'--no-unsafe-inline': `build app without introducing inline scripts`,
3230
'--target': `app | lib | wc | wc-async (default: ${defaults.target})`,
3331
'--inline-vue': 'include the Vue module in the final bundle of library or web component target',
3432
'--formats': `list of output formats for library builds (default: ${defaults.formats})`,

packages/@vue/cli-service/lib/commands/build/resolveAppConfig.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ module.exports = (api, args, options) => {
2424
if (!args.moduleBuild) {
2525
// Inject plugin to extract build stats and write to disk
2626
config
27-
.plugin('modern-mode-legacy')
28-
.use(ModernModePlugin, [{
29-
targetDir,
30-
isModuleBuild: false
31-
}])
27+
.plugin('modern-mode-legacy')
28+
.use(ModernModePlugin, [{
29+
targetDir,
30+
isModernBuild: false
31+
}])
3232
} else {
3333
config
3434
.plugin('safari-nomodule-fix')
3535
.use(SafariNomoduleFixPlugin, [{
36-
unsafeInline: args['unsafe-inline'],
37-
// as we may generate an addition file asset (if `no-unsafe-inline` specified)
36+
// as we may generate an addition file asset (if Safari 10 fix is needed)
3837
// we need to provide the correct directory for that file to place in
3938
jsDirectory: require('../../util/getAssetPath')(options, 'js')
4039
}])

0 commit comments

Comments
 (0)