简体   繁体   English

react-hot-loader的webpack输出文件会去哪里?

[英]Where do the webpack output files from the react-hot-loader go?

Let me preface this by saying that everything I have set up works, this is just a question that's nagging me that I would love to get an answer for. 首先,我要说的是我已设置的所有内容都可以正常工作,这只是一个困扰我的问题,我很想得到答案。 I'm using the react-hot-boilerplate project ( https://github.com/gaearon/react-hot-boilerplate ). 我正在使用react-hot-boilerplate项目( https://github.com/gaearon/react-hot-boilerplate )。 However, in webpack.config.js , this setting is confusing me to no end: 但是,在webpack.config.js ,此设置使我困惑webpack.config.js

output: {
  path: path.join(__dirname, 'dist'),
  filename: 'bundle.js',
  publicPath: '/static/'
},

In this config, it looks like the output file should go into the dist folder in root of the project. 在此配置中,看起来输出文件应该进入项目根目录下的dist文件夹。 Even if I manually create the dist folder (which I know I shouldn't have to do), no file gets outputted. 即使我手动创建dist文件夹(我知道我不必这样做),也不会输出任何文件。 Yet everything works totally fine; 但是,一切都很好。 the app loads and will hot-reload if I change something in the components. 如果我更改了组件中的某些内容,则该应用会加载并会热重新加载。 Where is this output file actually going? 该输出文件实际上在哪里?

All of the heavy lifting for react-hot-boilerplate (in terms of hot reloading files) is done by the webpack-dev-server dependency. react-hot-boilerplate的所有繁重工作(就热重载文件而言)都是由webpack-dev-server依赖项完成的。

webpack-dev-server in turn uses webpack-dev-middleware to handle the serving of the files (from express). webpack-dev-server依次使用webpack-dev-middleware来处理文件的提供(来自express)。

This bit of documentation about Webpack Dev Server should give you a good overview about how the mechanism works: 关于Webpack Dev Server的这些文档应该为您提供有关该机制如何工作的良好概述:

Using this config webpack-dev-server will serve the static files in your build folder and watch your source files for changes. 使用此配置webpack-dev-server将在您的构建文件夹中提供静态文件,并监视您的源文件中的更改。 When changes are made the bundle will be recompiled. 进行更改后,捆绑包将重新编译。 This modified bundle is served from memory at the relative path specified in publicPath (see API). 修改后的捆绑包是从publicPath中指定的相对路径的内存中提供的(请参阅API)。 It will not be written to your configured output directory. 它不会被写入您配置的输出目录。 Where a bundle already exists at the same url path the bundle in memory will take precedence. 在同一个url路径中已经存在捆绑软件的情况下,内存中的捆绑软件将优先。

For example with the configuration above your bundle will be available at localhost:8080/assets/bundle.js 例如,使用上述配置,您的捆绑包将在localhost:8080 / assets / bundle.js上提供

And this is a good bit from the webpack-dev-middleware docs: 这是webpack-dev-middleware文档中的一个好地方:

The webpack-dev-middleware is a small middleware for a connect-based middleware stack. webpack-dev-middleware是用于基于连接的中间件堆栈的小型中间件。 It uses webpack to compile assets in-memory and serve them. 它使用webpack在内存中编译资产并提供服务。 When a compilation is running every request to the served webpack assets is blocked until we have a stable bundle. 当编译运行时,对所提供的Webpack资产的所有请求都会被阻止,直到我们拥有稳定的捆绑包为止。

So, inside the dev server, the files are written to an in memory-file system and then served. 因此,在开发服务器内部,将文件写入内存文件系统中,然后提供服务。 The assets endpoint serves files from the in-memory location as well as creates a web socket connection to push down further changes. 资产终结点从内存中的位置提供文件,并创建Web套接字连接以下推进一步的更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM