我有一个reactjs应用,我想将其集成到我刚刚创建的Rails Webpacker项目中。
我是否必须将下面的webpack.config.dev.js文件转换为我的webpacker.yml文件?
我不确定webpacker的功能是什么,希望以前做过的人能有所启发。
var path = require('path');
var process = require('process');
var webpack = require('webpack');
var _ = require('./webpack.config.dev.js');
var _package = require('./package.json');
_.entry = './src/index';
_.plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
},
'ENV_DEVTOOLS_DISABLED': JSON.stringify(process.env.DEVTOOLS_DISABLED),
'ENV_API_ROOT': JSON.stringify(process.env.API_ROOT),
'ENV_APP_ROOT': JSON.stringify(process.env.APP_ROOT),
'ENV_VERSION': JSON.stringify(_package.version)
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compressor: {
warnings: false
}
}),
// new webpack.optimize.AggressiveMergingPlugin()
];
module.exports = _;
我会在我的启动节点应用程序中引用它:
var express = require('express');
var path = require('path');
var process = require('process');
var webpack = require('webpack');
var config = require('../webpack.config.dev');
var app = express();
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '../src/index.html'));
});
var port = process.env.MANAGER_PORT || 4044;
app.listen(port, 'example.com', function(err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:' + port);
});