我最近从Webpack v1升级到v3,现在构建无法从应用程序识别JSX语法。我从here跟随v1到v2的文档,然后安装了v3。
webpack.config.js
const webpack = require('webpack');
const precss = require('precss');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const jsPresets = [
['env', {
targets: {
chrome: 52,
browsers: [
'last 4 versions',
'safari >= 7',
],
},
} ],
'babel-preset-stage-2',
];
const baseConfig = {
entry: [
'babel-polyfill',
'antd/dist/antd.css',
'./wp-content/plugins/custom/js/router',
'./wp-content/plugins/custom/js/legacy/header',
'./node_modules/m-react-splitters/lib/splitters.css',
'react-s-alert/dist/s-alert-default.css',
'react-s-alert/dist/s-alert-css-effects/flip.css',
'react-s-alert/dist/s-alert-css-effects/bouncyflip.css',
'react-quill/dist/quill.snow.css',
],
output: {
path: path.resolve(__dirname, './wp-content/plugins/custom/js'),
filename: 'custom.js',
},
module: {
rules: [{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader?-url',
'postcss-loader',
]
}),
}, {
// whatwg-fetch use Promsie which IE11 doesn't support
test: /\.js$/,
include: [/whatwg-.*/],
use: {
loader: 'babel-loader'
},
}, {
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: jsPresets,
plugins: [
['import', { libraryName: 'antd' }],
'transform-class-properties',
'transform-es2015-arrow-functions',
],
},
},
}],
},
plugins: [
new ExtractTextPlugin({
filename: '../css/custom.css',
allChunks: true,
}),
new webpack.ProvidePlugin({
React: 'react',
Intl: 'imports-loader?this=>global!exports-loader?global.Intl!intl',
}),
],
};
module.exports = baseConfig;
webpack尝试捆绑后终端上抛出错误消息:
我不确定这里有什么问题,感谢任何帮助。
答案 0 :(得分:1)
就我在你的预设中看到的那样,你没有使用反应预设。你需要像这样安装babel-preset-react:
npm install --save-dev babel-cli babel-preset-react
然后在您的预设中添加"反应"这应该是透明的。