【问题标题】:gulp webpack-dev-server changes not appliedgulp webpack-dev-server 更改未应用
【发布时间】:2016-06-13 11:14:54
【问题描述】:

尝试使用 gulp 设置 webpack-dev-server。当发生更改时,webpack-dev-server 似乎重新构建了 bundle.js 文件,但如果我刷新页面,它仍然是一样的。我得手动用webpack编译bundle.js,每次都要重启服务器。

gulpfile.js

gulp.task('webpack-dev-server', function() {
    var compiler = webpack(require('./webpack.config'));
    new WebpackDevServer(compiler, {
        contentBase: 'public',
        historyApiFallback: true,
        progress: true,
        inline: true
    }).listen(8000, 'localhost', (err) => {
                if(err) throw new $.util.PluginError('webpack-dev-server', err);
                $.util.log('[webpack-dev-server]', 'http://localhost:8000');
    });
});

webpack.config.js

module.exports = {
    entry: [
        './src/index.js'
    ],
    output: {
        path: __dirname + '/public/js',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.(jsx|js)$/,
                loader: "babel-loader",
                exclude: /node_modules/,
                query: {
                    presets: ["es2015", "react"]
                }
            }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    devServer: {
        contentBase: 'public',
        inline: true,
        progress: true
    }
};

【问题讨论】:

    标签: javascript gulp webpack webpack-dev-server


    【解决方案1】:

    发现问题:contentBase 使用磁盘的根作为项目的根,而不是项目文件夹本身。所以路径变成了“F:\public”。我将其更改为 contentBase: __dirname + 'public' 并且可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 2017-06-06
      • 2017-08-07
      • 2017-10-13
      相关资源
      最近更新 更多