【发布时间】:2016-01-03 20:15:38
【问题描述】:
这个问题与that other question有关,我正在尝试打包我的react应用程序(html和javascript)并将其部署在IIS上的另一台机器上。
当我运行npm run build:prod 时,我得到一个错误:index.js Line 1: Unexpected reserved word. You may need an appropriate loader to handle this file type.
这是我在 package.json 中的scripts 部分:
"scripts": {
"start": "node server.js",
"build:prod": "webpack --optimize-minimize --config webpack.prod.config.js",
"lint": "eslint src"
},
webpack.prod.config.js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist_prod'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" })
],
externales: { "jquery": "jQuery", "$": 'jQuery' },
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{ test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
]
}
};
以及完美的 index.js 文件,因为错误提到了它:
import React from 'react';
import App from './App';
var myApp = React.render(
<App />,
document.getElementById('root')
);
【问题讨论】:
-
我认为你缺少一个加载器来转换你的 ES6 和你的 JSX。也许你缺少 babel 和 jsx 加载器?
-
我认为你是对的
标签: javascript reactjs npm webpack packaging