我刚刚开始使用 Webpack,所以我已经掌握了足够危险的知识,而且我确信我已经把我的配置文件弄得一团糟。但它非常接近于survivorJS 示例,它在我的机器上运行没有问题。但是,当我加载我的应用程序时,我会在控制台中收到一系列关于某些 websocket 握手失败的消息。
一切都加载两次。每当我更新文件时,除了重复上述所有错误之外,我还会遇到更多错误。
知道为什么它对我这么生气吗?
这是我的 webpack 配置(构建工作正常):
require('dotenv').config();
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const pkg = require('./package.json');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'src/client'),
style: path.join(__dirname, 'src/client/components/main.scss'),
build: path.join(__dirname, 'dist/client')
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: {
app: PATHS.app,
style: PATHS.style
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: PATHS.build,
chunkFilename: '[chunkhash].js'
},
module: {
loaders: [
{
test: /\.js(x?)$/,
loaders: ['babel?cacheDirectory'],
include: PATHS.app
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'node_modules/html-webpack-template/index.ejs',
title: 'Score Fluent',
appMountId: 'app',
inject: false
})
]
}
// Add dev server config
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
output: {
filename: '[name].js',
},
module: {
loaders: [
{
test: /\.s(c|a)ss$/,
loaders: ['style', 'css', 'sass'],
include: PATHS.app
}
]
},
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: process.env.HOST,
port: process.env.PORT
},
devtool: 'eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});
}
// Just build it
if (TARGET === 'build' || TARGET === 'stats') {
module.exports = merge(common, {
entry: {
vendor: Object.keys(pkg.dependencies).filter(function(v) {
return v !== 'alt-utils'
})
},
output: {
filename: '[name].[chunkhash].js'
},
module: {
loaders: [
{
test: /\.s(c|a)ss$/,
loader: ExtractTextPlugin.extract('style', 'css', 'sass'),
include: PATHS.app
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new CleanPlugin([PATHS.build]),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new ExtractTextPlugin('[name].[chunkhash].css'),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
});
}