我正在构建一个包含可重用组件的包,我想将其发布到 NPM。
.babelrc
{
"presets": ["es2015", "react"]
}
.eslintrc
{
root: true,
parser: 'babel-eslint',
plugins: [/*'import', */'jsx-a11y', 'react'],
env: {
browser: true,
commonjs: true,
es6: true,
jest: true,
node: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
generators: true,
experimentalObjectRestSpread: true
}
},
settings: {
'import/ignore': [
'node_modules',
'\\.(json|css|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$',
],
'import/extensions': ['.js'],
'import/resolver': {
node: {
extensions: ['.js', '.json']
}
}
}
}
package.json
{
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1"
},
"dependencies": {
"react": "^16.4.2"
}
}
我希望能够像这样“解压缩”一个 JS 对象:var x = {...this.props}
但是在运行我的构建脚本时,它会卡在...this.props
零件上。
我需要什么来翻译这个语法?
您可以考虑使用变换对象休息传播插件。在使用部分查看如何将其添加到您的 Babel 配置中。你可以把它添加到你.babelrc
喜欢的地方:
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
“舞台”预设在当前的 Babel 版本中已被弃用。
虽然babel-preset-env
也可能提供此功能,但它并不是针对您所问问题的需求——它有更广泛的用例,尽管我同意您至少应该考虑它。在此处了解更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句