Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
v2.2.0的Webpack.config_Webpack_Webpack 2 - Fatal编程技术网

v2.2.0的Webpack.config

v2.2.0的Webpack.config,webpack,webpack-2,Webpack,Webpack 2,Webpack已更改很多,找不到适用于v2.2.0的有效Webpack.config 我确实想将Webpack.config从2.1迁移到2.2 我犯了很多这样的错误: ERROR in ./src/styles/core.scss Module build failed: ReferenceError: window is not defined 那么,我需要改变什么来使用v2.2呢 我的档案是: import webpack from 'webpack'; import cssnano f

Webpack已更改很多,找不到适用于v2.2.0的有效Webpack.config

我确实想将Webpack.config从2.1迁移到2.2

我犯了很多这样的错误:

ERROR in ./src/styles/core.scss
Module build failed: ReferenceError: window is not defined
那么,我需要改变什么来使用v2.2呢

我的档案是:

import webpack from 'webpack';
import cssnano from 'cssnano';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

const cssModulesLoader = [
  'css?sourceMap&-minimize',
  'modules',
  'importLoaders=1',
  'localIdentName=[name]__[local]__[hash:base64:5]'
].join('&');

export default function(options) {
  const webpackConfig = {
    entry: [
      './src/index.js'
    ],
    output: {
      path: __dirname + '/public',
      publicPath: '/',
      filename: 'bundle.[hash].js'
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: './src/index.html',
        favicon: './src/static/favicon.png',
        filename: 'index.html',
        inject: 'body'
      }),
      new ExtractTextPlugin({
        filename: 'styles.[hash].css',
        allChunks: true
      })
    ],
    module: {
      loaders: [{
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          cacheDirectory: true,
          plugins: ['transform-runtime'],
          presets: [
            ['es2015', {'modules': false}],
            'react',
            'stage-0'
          ],
          env: {
            production: {
              presets: ['react-optimize'],
              compact: true
            },
            test: {
              plugins: [
                ['__coverage__', {'only': 'src/'}],
                'babel-plugin-rewire'
              ]
            }
          }
        }
      }, {
        test: /\.json$/,
        loader: 'json'
      }, {
        test: /\.html$/,
        loader: 'html'
      }, {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract({
          disable: options.dev,
          fallbackLoader: 'style-loader',
          loader: [cssModulesLoader, 'postcss', 'sass?sourceMap']
        })
      }, {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: ['css-loader', 'postcss']
        })
      }]
    },
    resolve: {
      modules: ['node_modules'],
      extensions: ['', '.js', '.jsx', '.json'],
      alias: {}
    },
    globals: {},
    postcss: [
      cssnano({
        autoprefixer: {
          add: true,
          remove: true,
          browsers: ['last 2 versions']
        },
        discardComments: {
          removeAll: true
        },
        discardUnused: false,
        mergeIdents: false,
        reduceIdents: false,
        safe: true,
        sourcemap: true
      })
    ]
  };

  if (options.dev) {
    webpackConfig.devtool = 'source-map';
    webpackConfig.plugins.push(
      new webpack.DefinePlugin({
        '__DEV_': true
      })
    );
  }

  if (options.test) {
    process.env.NODE_ENV = 'test';
    webpackConfig.devtool = 'cheap-module-source-map';
    webpackConfig.resolve.alias.sinon = 'sinon/pkg/sinon.js';
    webpackConfig.module.noParse = [
      /\/sinon\.js/
    ];
    webpackConfig.module.loaders.push([
      {
        test: /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
        loader: 'imports?define=>false,require=>false'
      }
    ]);
    // Enzyme fix, see:
    // https://github.com/airbnb/enzyme/issues/47
    webpackConfig.externals = {
      'react/addons': true,
      'react/lib/ExecutionEnvironment': true,
      'react/lib/ReactContext': 'window'
    };
    webpackConfig.plugins.push(
      new webpack.DefinePlugin({
        '__COVERAGE__': options.coverage,
        '__TEST_': true
      })
    );
  }

  if (options.prod) {
    process.env.NODE_ENV = 'production';
    webpackConfig.plugins.push(
      new webpack.LoaderOptionsPlugin({
        minimize: true,
        debug: false
      }),
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': JSON.stringify('production'),
          '__PROD__': true
        }
      }),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new webpack.optimize.DedupePlugin(),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          unused: true,
          dead_code: true,
          warnings: false
        }
      })
    );
  }

  if (options.deploy) {
    webpackConfig.output.publicPath = '/MoonMail-UI/';
  }

  return webpackConfig;
}

对于尝试从Webpack 2.1迁移到2.2的任何人,以下是我的新配置文件:

package.json webpack.config.js postss.config.js 如果不使用url解析,则可以删除以下内容:

{ loader: 'sass-loader'}, // remove this line
{ loader: 'resolve-url-loader'} // remove this line

有关这方面的更多信息,请访问此处:

对于尝试从Webpack 2.1迁移到2.2的任何人,这里是我的新配置文件:

package.json webpack.config.js postss.config.js 如果不使用url解析,则可以删除以下内容:

{ loader: 'sass-loader'}, // remove this line
{ loader: 'resolve-url-loader'} // remove this line

有关这方面的更多信息可在此处找到:

你的问题是什么?@Jordan让我编辑使其更清楚你的问题是什么?@Jordan让我编辑使其更清楚
module.exports = {
    plugins: {
        'postcss-import': {},
        'postcss-cssnext': {
            browsers: ['last 2 versions', '> 5%'],
        },
    },
}
{ loader: 'sass-loader'}, // remove this line
{ loader: 'resolve-url-loader'} // remove this line