我正在尝试使用babel& amp做一个单独的js包文件webpack,我经常得到这些解析错误,好像适当的babel转换根本不起作用。我正在为babel使用'react-native'预设,其中包括以下插件:
'babel-plugin-react-transform'
'babel-plugin-syntax-async-functions'
'babel-plugin-syntax-class-properties'
'babel-plugin-syntax-trailing-function-commas'
'babel-plugin-transform-class-properties'
'babel-plugin-transform-es2015-arrow-functions'
'babel-plugin-transform-es2015-block-scoping'
'babel-plugin-transform-es2015-classes'
'babel-plugin-transform-es2015-computed-properties'
'babel-plugin-transform-es2015-constants'
'babel-plugin-transform-es2015-destructuring'
'babel-plugin-transform-es2015-modules-commonjs'
'babel-plugin-transform-es2015-parameters'
'babel-plugin-transform-es2015-shorthand-properties'
'babel-plugin-transform-es2015-spread'
'babel-plugin-transform-es2015-template-literals'
'babel-plugin-transform-flow-strip-types'
'babel-plugin-transform-object-assign'
'babel-plugin-transform-object-rest-spread'
'babel-plugin-transform-react-display-name'
'babel-plugin-transform-react-jsx'
'babel-plugin-transform-regenerator'
'babel-plugin-transform-es2015-for-of'
所以这个插件'babel-plugin-syntax-class-properties'应该做我正在寻找的转换,但由于某种原因它不起作用。即使我手动将此插件添加到.babelrc文件中,我也得到相同的输出。这是我得到的错误:
ERROR in ./~/@exponent/react-native-navigator/ExNavigator.js
Module parse failed: /Users/Arbor/Desktop/ArborMobileApp/backend/node_modules/@exponent/react-native-navigator/ExNavigator.js Unexpected token (24:16)
You may need an appropriate loader to handle this file type.
|
| export default class ExNavigator extends React.Component {
| static Styles = ExNavigatorStyles;
| static SceneConfigs = ExSceneConfigs;
| static Icons = ExNavigatorIcons;
@ ./logic/initialize.js 14:175-218
这是我的.babelrc文件:
{
"presets": ["react-native"],
}
我的webpack.config.js:
const webpack = require('webpack');
module.exports = {
entry: './entryPoint.js',
output: {
path: './release',
filename: 'basecomponents.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
}
};
和package.json:
{
"name": "react-native-base-components",
"private": true,
"version": "0.0.1",
"description": "",
"main": "entryPoint",
"dependencies": {
"@exponent/react-native-navigator": "^0.4.2",
"react-native-orientation": "^1.15.0"
},
"devDependencies": {
"babel-core": "^6.5.2",
"babel-loader": "^6.2.3",
"webpack": "^2.0.7-beta"
},
"scripts": {
"build": "rm -f dist/basecomponents.js && clear && node_modules/.bin/webpack --progress"
}
}
我做错了什么?感谢。