-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from surmon-china/master
v1.15.0 支持 polyfill
- Loading branch information
Showing
45 changed files
with
1,058 additions
and
447 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file clean dist | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
/* | ||
/** | ||
* @file chunks | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
||
module.exports = { | ||
common: 'fec__common', | ||
manifest: 'fec__manifest' | ||
manifest: 'fec__manifest', | ||
polyfill: 'fec__polyfill' | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file file names | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file all valid transforms | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file generate dist files | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file prepare behaviors | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file run unit test | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file upload files | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file config | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file env info | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file util methods | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file logger | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file paths | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file project relative util methods | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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,48 @@ | ||
/** | ||
* @file add polyfill | ||
* @author Surmon <i@surmon.me> | ||
*/ | ||
|
||
const path = require('path') | ||
const update = require('immutability-helper') | ||
const VirtualModulesPlugin = require('webpack-virtual-modules') | ||
|
||
const buildEnv = require('../../utils/build-env') | ||
const chunks = require('../../constants/chunks') | ||
|
||
module.exports = (webpackConfig, srcDir, srcPath, { addPolyfill }) => { | ||
const isProdEnv = buildEnv.get() === buildEnv.prod | ||
|
||
if (!addPolyfill || !isProdEnv) { | ||
return webpackConfig | ||
} | ||
|
||
const mockFile = `${chunks.polyfill}.js` | ||
|
||
return update(webpackConfig, { | ||
entry: { | ||
$merge: { | ||
/** | ||
* 此处有两点需求: | ||
* 1. 经过反复测试和确认,Babel 似乎认工作路径,如果 polyfill 与项目程序本身的路径不一致,则 useBuiltIns 失效 | ||
* 2. 所以只能造一个假的路径为项目路径的虚拟文件,以模拟 '/xxx/project/src/polyfill.js' | ||
* 3. VirtualModulesPlugin 插件目前可确认的最高支持在 Webpack v4,如果后期升级 Webpack 则需检测此处 | ||
X `[chunks.polyfill]: '@babel/polyfill'` -> 无法被 Babel 理解并替换 | ||
X `path.resolve(__dirname, ... 'polyfill.js')` -> 无法产出合乎预期的包,始终为全量的 polyfill | ||
*/ | ||
[chunks.polyfill]: path.resolve(srcPath, mockFile) | ||
} | ||
}, | ||
plugins: { | ||
$push: [ | ||
new VirtualModulesPlugin({ | ||
[ | ||
path.join('./', srcDir, '/') + mockFile | ||
]: ( | ||
`require('@babel/polyfill')` | ||
) | ||
}) | ||
] | ||
} | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
/* | ||
/** | ||
* @file config for common-chunks | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
||
const update = require('immutability-helper') | ||
const chunks = require('../../constants/chunks') | ||
const buildEnv = require('../../utils/build-env') | ||
|
||
module.exports = (config, optimization) => { | ||
const { addPolyfill } = optimization | ||
const optCommon = optimization.extractCommon | ||
const optVendor = optimization.extractVendor | ||
|
||
const chunksName = ( | ||
addPolyfill && buildEnv.get() === buildEnv.prod | ||
? chunk => chunk.name !== chunks.polyfill | ||
: 'all' | ||
) | ||
|
||
const cacheGroups = {} | ||
|
||
if (optVendor) { | ||
cacheGroups[optVendor] = { | ||
name: optVendor, | ||
chunks: 'all', | ||
chunks: chunksName, | ||
minSize: Infinity | ||
} | ||
} | ||
|
||
const splitChunksOptions = optCommon | ||
? { chunks: 'all', name: chunks.common, cacheGroups } | ||
: { chunks: 'all', name: chunks.common, minSize: Infinity, cacheGroups } | ||
? { chunks: chunksName, name: chunks.common, cacheGroups } | ||
: { chunks: chunksName, name: chunks.common, minSize: Infinity, cacheGroups } | ||
|
||
return update(config, { optimization: { splitChunks: { $set: splitChunksOptions } } }) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file compress-image | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file config for configure postcss | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/** | ||
* @file config for devServer proxy | ||
* @author nighca <nighca@live.cn> | ||
*/ | ||
|
Oops, something went wrong.