2

我真的很喜欢这个将前端与后端分离的样板背后的概念。我正在尝试从 WebPack 开始更新整个样板。样板中包含的版本是 WebPack 1。我尝试将其升级到版本 3。

显然,我只需要将其升级到版本 2,因为升级到版本 3 很顺利,并且仅通过更新 WebPack 通过命令行完成。我当然主要遵循官方指南和其他一些单独的资源来尝试修改 webpack.config.js文件。我最终得到了以下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];
  }*/
};

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

4

0 回答 0