简体   繁体   English

Webpack-dev-server不会在更改时构建文件

[英]Webpack-dev-server doesn't build files on change

So I have the following webpack configuration : 所以我有以下webpack配置:

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 --watch the file does build in the /dist/ folder at every change. 问题是,当我做webpack --watch ,文件会在每次更改时都在/dist/文件夹中构建。 Yet when I run the webpack-dev-server the files don't even build. 然而,当我运行webpack-dev-server ,文件甚至无法构建。 Why is that? 这是为什么?

Please help. 请帮忙。

The reason you are not seeing files emitted into your dist folder is because webpack-dev-server uses an in-memory filesystem 您没有看到文件发送到dist文件夹的原因是因为webpack-dev-server使用内存中的文件系统

This allows for extremely fast incremental builds when your code changes. 这可以在代码更改时实现极快的增量构建。 This was an intentional design on our part. 这是我们的故意设计。 You can view the resulting code in your browser and never need to reference those files. 您可以在浏览器中查看生成的代码,而不需要引用这些文件。

It is not recommended by us, for the sake of build performance, but you can look in to plugins like write-file-webpack-plugin if you need this feature. 我们不建议为了构建性能,但如果需要此功能,可以查看write-file-webpack-plugin等插件

'webpack' writes your bundle to disk, whereas 'webpack-dev-server' loads the bundle into memory. 'webpack'将你的包写入磁盘,而'webpack-dev-server'将包装入内存。 So when running the latter command you wont see a new 'bundle.js' file appear in your file system, even though you should see output to the console reporting the bundling and the start up of the dev server). 因此,当运行后一个命令时,您将看不到新的“bundle.js”文件出现在您的文件系统中,即使您应该看到输出到控制台报告捆绑和启动服务器的启动。

The output.publicPath config key determines the location of the in-memory bundle on the host dev server. output.publicPath配置密钥确定主机dev服务器上的内存中软件包的位置。 So if you set the publicPath to 'dist' then the index.html served by the webpack dev server will need a script tag in order to reference the bundle. 因此,如果将publicPath设置为'dist',那么webpack dev服务器所服务的index.html将需要一个脚本标记才能引用该bundle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果webpack-dev-server导入命名导出文件,则它们不会监视/重新编译文件 - webpack-dev-server doesn't watch/recompile files if they import named exports Webpack-Dev-Server未显示有关更改的最新文件 - Webpack-Dev-Server not showing latest files on change webpack-dev-server historyApiFallback 不起作用 - webpack-dev-server historyApiFallback doesn't work webpack-dev-server不会在子文件夹中编译React组件 - webpack-dev-server doesn't compile React components in subfolders webpack-dev-server内联标志不起作用 - webpack-dev-server inline flag doesn't work Webpack - 在 webpack-dev-server 上链接其他 Pug 页面不起作用 - Webpack - linking other Pug pages on webpack-dev-server doesn't work Webpack-dev-server 抛出有关 node_modules/webpack-dev-server 中缺少的文件的错误 - Webpack-dev-server throws errors about files missing in node_modules/webpack-dev-server webpack配置webpack-dev-server不会即时编译文件 - webpack configuration webpack-dev-server does not compile files on the fly 使用 webpack 4(和 webpack-dev-server)将 css 注入到多个 html 文件中 - Injecting css into multiple html files with webpack 4 (and webpack-dev-server) webpack-dev-server 不重新编译(JS 文件和 SCSS 文件) - webpack-dev-server not recompiling (JS files AND SCSS files)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM