1

So I have the following webpack configuration :

import path from 'path';

module.exports = {
    entry: {
    index: './dev/index.js'
    },
    output: {
        path: path.join(__dirname, 'dist'),
        publicPath: './dist/',
        filename: 'bundle.js',
        chunkFilename: '[id].bundle.js'
    },
    module:{
        loader:{
            test: /\.js$/,
            exclude:path.resolve(__dirname, "node_modules"),
            loader: 'js'
        }
    }

};

The problem is that when I do webpack --watchthe file does build in the /dist/ folder at every change. Yet when I run the webpack-dev-server the files don't even build. Why is that?

Please help.

4

2 回答 2

5

您没有看到文件发送到 dist 文件夹的原因是 webpack-dev-server 使用内存文件系统

当您的代码更改时,这允许极快的增量构建。这是我们有意的设计。您可以在浏览器中查看生成的代码,而无需引用这些文件。

为了构建性能,我们不推荐它,但是如果您需要此功能,可以查看诸如write-file-webpack-plugin 之类的插件。

于 2016-08-20T21:18:34.537 回答
0

'webpack' 将你的包写入磁盘,而'webpack-dev-server' 将包加载到内存中。因此,当运行后一个命令时,您不会在文件系统中看到新的“bundle.js”文件,即使您应该看到控制台的输出报告捆绑和开发服务器的启动)。

output.publicPath 配置键确定主机开发服务器上内存包的位置。因此,如果您将 publicPath 设置为 'dist',那么 webpack 开发服务器提供的 index.html 将需要一个 script 标签来引用包。

于 2016-08-20T21:13:49.523 回答