Skip to content

Commit 7df0c58

Browse files
WilsonLiu95haoqunjiang
authored andcommittedFeb 28, 2019
feat: add entryFiles option, allowing explicit polyfill injection to specified files (#3470)
1 parent bd57f15 commit 7df0c58

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed
 

‎packages/@vue/babel-preset-app/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ Set to `false` to disable JSX support.
9797
- Default: `false`.
9898

9999
Setting this to `true` will generate code that is more performant but less spec-compliant.
100+
101+
### entryFiles
102+
103+
- Default: `[]`
104+
105+
Multi page repo use entryFiles to ensure inject polyfills to all entry file.

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ module.exports = (context, options = {}) => {
5252
forceAllTransforms,
5353
decoratorsBeforeExport,
5454
decoratorsLegacy,
55+
// entry file list
56+
entryFiles,
5557

5658
// Undocumented option of @babel/plugin-transform-runtime.
5759
// When enabled, an absolute path is used when importing a runtime helper atfer tranforming.
@@ -103,7 +105,7 @@ module.exports = (context, options = {}) => {
103105
ignoreBrowserslistConfig,
104106
configPath
105107
})
106-
plugins.push([require('./polyfillsPlugin'), { polyfills }])
108+
plugins.push([require('./polyfillsPlugin'), { polyfills, entryFiles }])
107109
} else {
108110
polyfills = []
109111
}

‎packages/@vue/babel-preset-app/polyfillsPlugin.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// add polyfill imports to the first file encountered.
2-
module.exports = ({ types }) => {
2+
module.exports = ({ types }, { entryFiles = [] }) => {
33
let entryFile
44
return {
55
name: 'vue-cli-inject-polyfills',
66
visitor: {
77
Program (path, state) {
8-
if (!entryFile) {
9-
entryFile = state.filename
10-
} else if (state.filename !== entryFile) {
8+
if (entryFiles.length === 0) {
9+
if (!entryFile) {
10+
entryFile = state.filename
11+
} else if (state.filename !== entryFile) {
12+
return
13+
}
14+
} else if (!entryFiles.includes(state.filename)) {
1115
return
1216
}
1317

0 commit comments

Comments
 (0)
Please sign in to comment.