简体   繁体   English

带有React Hot loader的publicPath

[英]publicPath with react hot loader

I'm not quite sure what the publicPath in webpack does. 我不太确定publicPath中的webpack是做什么的。 Specifically, output.publicPath . 具体来说output.publicPath In the github docs, I see this 在github文档中,我看到了

https://github.com/webpack/docs/wiki/configuration#outputpublicpath https://github.com/webpack/docs/wiki/configuration#outputpublicpath

The output.path from the view of the Javascript / HTML page. Javascript / HTML页面视图中的output.path。

For reactjs hot loading, I have 对于reactjs热加载,我有

output: {
        path: path.resolve('./public/bundle/'),
        // path: './public/bundle',
        filename: 'main.js',
        // Webpack dev server is bound to port 8080, we have to force use of absolute URL, using the publicPath property
        publicPath: 'http://localhost:8080/public/bundle/'
    },

Does this mean that the built webpack files ( main.js ) is placed in my dev-server http://localhost:8080/public/bundle/ ? 这是否意味着已将构建的webpack文件( main.js )放置在我的dev-server http:// localhost:8080 / public / bundle /中

Yep, Webpack needs to know where you'll host the generated bundle file (or any other assets it generates) so that it can request additional chunks or files that are loaded from file-loader or url-loader. 是的,Webpack需要知道您将在何处托管生成的捆绑文件(或其生成的任何其他资产),以便它可以请求从文件加载器或url加载器加载的其他块或文件。 Hence in this case, when you start your webpack-dev-server, you'll be able to access your bundle file at: http://localhost:8080/public/bundle/main.js (any related assets like images, commonchunk, fonts, etc will be under that path) 因此,在这种情况下,当您启动webpack-dev-server时,将能够访问以下位置的捆绑文件: http://localhost:8080/public/bundle/main.js (任何相关资产,例如图像,commonchunk ,字体等将位于该路径下)

Outside of dev-server, you can use it to define the location of your assets (from a custom directory or even a CDN) 在dev-server外部,您可以使用它来定义资产的位置(从自定义目录甚至CDN)

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

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