1

我在webpack.validateSchema is not a function设置 webpack 并在下面做出反应时遇到了这个问题,我分享了我的webpack.config.js

const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
    app: path.join(__dirname, 'app'),
    build: path.join(__dirname, 'build')
};

const common = {
    entry: {
        app: PATHS.app
    },
    output: {
        path: PATHS.build,
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.css$/,
                loaders: ['style','css'],
                include: PATHS.app,
            }
        ]
    }
};

if(TARGET === 'start' || !TARGET){
    module.exports = merge(common, {
        devtool: 'eval-source-map',
        devServer: {
            contentBase: PATHS.build,
            historyApiFallback: true,
            hot: true,
            inline: true,
            progress: true,
            stats: 'errors-only',
            host: process.env.HOST,
            port: process.env.PORT || 3000
        },
        plugins: [
            new webpack.HotModuleReplacementPlugin()
        ]
    });
}
if(TARGET === 'build'){
    module.exports = merge(common, {});
}
4

1 回答 1

1

有几个错误需要修复:

  • 而不是extension: ['','.js','.jsx'],使用extensions: ['.js','.jsx']. 从 webpack 2 开始就不需要空条目,它会抱怨它。
  • 而不是['style','css'],使用['style-loader','css-loader']. 从 webpack 2 开始,它默认不提供快捷方式。
  • 而不是babel?cacheDirectory,使用babel-loader?cacheDirectory. 我可能会重写定义useoptions就像在webpack 书籍章节中一样。
于 2018-03-07T21:01:37.410 回答