我非常喜欢将前端与后端分开的this boilerplate背后的概念。 我试图从WebPack开始更新整个样板。 样板中包含的版本是WebPack 1。 我尝试将其升级到版本3.
显然我只需要将它升级到版本2,因为升级到版本3是顺利的,并且只通过更新WebPack通过命令行完成。 我主要跟随official guide和其他一些单独的资源来尝试修改 webpack.config.js 文件。 我最终得到了followong webpack.config.js 文件:
当我在客户端运行npm start时,我收到以下错误:
这是来自npm的调试文件。
var sGrid = require('s-grid');
var rupture = require('rupture');
var autoprefixer = require('autoprefixer');
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./app/App.js'
],
output: {
pathinfo: true,
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
publicPath: 'http://localhost:3000/'
},
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
//postcss: [autoprefixer],
context: __dirname,
minimize: true
//stylus: [sGrid, rupture]
}
}),
new HtmlWebpackPlugin({
title: 'React with Webpack and Redux - Meteor as a backend only!',
template: './index_template.ejs',
inject: 'body'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true, //in WebPack 2 it defaults to false so need to be explicitly set.
compress: {
warnings: true
}
})
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: ['babel-loader'] //'use' and 'loaders' are interchangeable
},
{
test: /\.css$/, //scss??
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2,
localIdentName: '[name]__[local]__[hash:base64:5]',
//plugins: autoprefixer,//WTF??
}
},
{
loader: 'postcss-loader',
options: {
plugins: function(){
return [autoprefixer]
}
}
}
]
//loader: 'style!css?sourceMap&importLoaders=2&localIdentName=[name]__[local]__[hash:base64:5]!postcss'
},
{
test: /\.styl$/,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options:{
sourceMap: true,
modules: true,
importLoaders: 2,
localIdentName: '[name]__[local]__[hash:base64:5]'
//plugins: sGrid, rupture
}
},
{
loader: 'postcss-loader',
options: {
plugins: function(){
return [autoprefixer]
}
}
},
{
loader: 'stylus-loader',
options: {
plugins: function(){
return [sGrid, rupture]
}
}
}
]
// loader: 'style!css?sourceMap&modules&importLoaders=2&localIdentName=[name]__[local]__[hash:base64:5]!postcss!stylus-loader'
},
{
test: /\.(png|jpg)$/,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'url-loader',
options:{
name: 'images/[name].[ext]',
limit: '8192' //Maybe INT????
}
}
]
//loader: 'url-loader?name=images/[name].[ext]&limit=8192'
}
]
},
resolve: {
//root: path.join(__dirname, '..', 'app'),
modules: [
path.join(__dirname, "app"), // 2 or 3 arguments??
"node_modules"
],
extensions: ['.js', '.jsx', '.json', '.css', '.styl', '.png', '.jpg', '.jpeg', '.gif'],
enforceModuleExtension: false
},
/* stylus: function () {
return [sGrid, rupture]
},*/
/* postcss: function () {
return [autoprefixer];
}*/
};

我非常感谢在这个问题上的任何帮助。