Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how do I override the public path of assets #459

Closed
Checksum opened this issue Oct 14, 2020 · 5 comments
Closed

Question: how do I override the public path of assets #459

Checksum opened this issue Oct 14, 2020 · 5 comments

Comments

@Checksum
Copy link

Is there a way to set the base path for assets, similar to webpack's publicPath setting? (https://webpack.js.org/guides/public-path/). I can't find that option for the CLI and can't seem to find a related issue as well.

@evanw
Copy link
Owner

evanw commented Oct 14, 2020

Can you say more about what you expect to happen? I don't use Webpack myself and the documentation you linked to doesn't tell me anything about what this feature does. What changes about the generated files when this setting is changed?

@dalcib
Copy link

dalcib commented Oct 14, 2020

react-native bundler also has a option to define a different output destination for the assets

--assets-dest

https://github.com/react-native-community/cli/blob/master/docs/commands.md#--assets-dest-string

@rtsao
Copy link
Contributor

rtsao commented Oct 15, 2020

The webpack build-time publicPath option (and runtime __webpack_public_path__ variable) is used to determine the path for loading assets and chunks (depending on the chunk loading method).

By default, for web bundles, webpack uses a JSONP method for dynamically loading chunks wherein <script> tags are appended to the DOM. The public path is essentially path prefix. Typically, you would set publicPath to something like /assets/ or https://cdn.example.com/

In addition to chunk loading, it also used to determine paths to other assets. For example, if you are using file-loader for .png files and have set the publicPath to a CDN:

import imgPath from "./my-image.png";

console.log(imgPath);
// https://cdn.example.com/my-image-e3087eadb38c752.png

Because esbuild currently only supports ESM output when using --splitting, I don't think there's a need for a public path option for chunk loading. However, this would be useful for the esbuild file loader.

@Checksum
Copy link
Author

Sorry for the pretty thin description, I really shouldn't create issues on my mobile. @rtsao has explained it well. The publicPath is the base URL for all the assets that are generated by a loader. For example:

const style = require("./style.css");
console.log(style);
// style.T5D2JDNG.css

If deploying this bundle to a CDN with a relative path, say https://cdn.example.com/v1/, the absolute path to the file should be https://cdn.example.com/v1/style.T5D2JDNG.css. By default publicPath is empty and hence is relative, but explicitly setting a base path is required quite often.

@jhohlfeld
Copy link

jhohlfeld commented May 26, 2023

Just for those like me stumbling across this and because the feature request is still open: here's a documented setting exactly as requested: https://esbuild.github.io/api/#public-path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants