-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel 7 转码的正确姿势 #4
Comments
请问babel7如何配置编译提供给别人用的库,我有一个库,之前转码很正常,昨天更新了一下包,就出问题了和项目的polyfill冲突了,想请教一下详细的配置去编译库 |
请参考我的建议,你的库只用 runtime 和 plugin-transform-runtime 来转码,不要用 polyfill 就行了 |
库的babel相关依赖现在是这样的,除了 devDependencies "devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.4.4",
} dependencies {
"@babel/runtime": "^7.5.5",
"core-js": "^3.1.4"
} .babelrc {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3"
}
]
]
} 另外,我是否需要在我的库的入口文件内引入 import 'core-js/stable';
import 'regenerator-runtime/runtime'; 库发布前会使用 感谢 |
现在工作有点忙,我一会儿会回复你。@jiaming743 |
@deepfunc 好的 谢谢 |
我一般会使用babel把 |
package.json "dependencies": {
"@babel/runtime": "..."
},
"devDependencies": {
"@babel/cli": "...",
"@babel/core": "...",
"@babel/preset-env": "...",
"@babel/plugin-transform-runtime": "..."
}, .babelrc {
"presets": [
["@babel/preset-env"]
],
"plugins": ["@babel/plugin-transform-runtime"]
} 依赖就这样就可以了,如果你需要用 state-x,参考我那篇文章的做法。 import 'core-js/stable';
import 'regenerator-runtime/runtime'; 这个不要用,这个是放在业务项目里面用的。如果你发布的是库的话,不要加这个,不然有全局污染。 |
对于Array.prototype.includes之类的实例方法,transform-runtime好像不会做处理,这种情况是否需要考虑呢? @deepfunc |
这个就是要交给业务项目处理呀,所以业务项目加入 polyfill 就可以了。因为你的库肯定是要给业务项目使用的。库一加就全局污染了 |
了解了,谢谢! |
不客气,觉得有用的话给个 star 哈,谢谢~ |
babelrc {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3"
}
]
]
} 另外问下这种配置是否会产生全局污染,好像是自动按需引入的 |
这个都是在业务项目里面用的,库里不需要,我上面有写到。 |
如果你对 本篇 有任何的疑问和建议,欢迎在这里提出来。
The text was updated successfully, but these errors were encountered: