这个问题与that other question有关,我试图打包我的反应应用程序(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')
);
答案 0 :(得分:1)
确实我错过了一个装载机:
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{ 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
]
感谢@Alexander O&#39; Mara