-
Notifications
You must be signed in to change notification settings - Fork 85
feature request: support __webpack_public_path__ for set publicPath dynamically at runtime #51
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
Comments
I'm not exactly sure what to do about that, @kmcclosk might know?? |
@faceyspacey I'm not familiar with how webpack works, but I just figured out how CSS files dynamically load on client side, and there are two simple ways to make this work:
// babel-plugin-universal-import/importCss.js
...
function getHref(chunkName) {
if (typeof window === 'undefined' || !window.__CSS_CHUNKS__) return null
return window.__PUBLIC_PATH__ ? window.__PUBLIC_PATH__ : '' + window.__CSS_CHUNKS__[chunkName]
} If those ways are ok, I can make a PR for this. |
#1 sounds about right. Go for it. |
@faceyspacey I just found another way: we can read Also, I think isn't it more reasonable that // webpack-flush-chunks/createApiWithCss.js
export const createCssHash = ({
assetsByChunkName,
publicPath
}: {
assetsByChunkName: FilesMap,
publicPath: string
}): CssChunksHash =>
Object.keys(assetsByChunkName).reduce((hash, name) => {
...
if (file) hash[name] = `${file}`
return hash
}, {}) // babel-plugin-universal-import/importCss.js
...
function getHref(chunkName) {
if (typeof window === 'undefined' || !window.__CSS_CHUNKS__) return null
return __webpack_public_path__ + window.__CSS_CHUNKS__[chunkName]
} |
I don't have much time to focus on this right now, so a change that might be just fine, but could potentially break things for lots of existing users, makes me nervous without being able to analyze it myself. Also ideally we don't touch the babel plugin. |
This means you don't need to set the `publicPath` option during setup and the loader will use webpack's native one. Resolves faceyspacey#51.
Will be resolved by #71 |
hi~
I'm using your great work react-universal-component with extract-css-chunks-webpack-plugin and have some troubles.
We have three different test environments: dev, oa, and pre, and they have different CDN like https://devwww.examplecdn.com, https://oawww.examplecdn.com. The static files only compiled on dev environment and copy to oa ,pre and online site, so we want set publicPath(CDN) dynamically at runtime.
Webpack document said we can use
__webpack_public_path__
to do this like:On server side , we manual add public path(it would be nice if webpack-flush-chunks can provide the public path option):
On client side, the javascript files works fine when I using
__webpack_public_path__
, but css files not.I saw extract-text-webpack-plugin have same problem but no one answer it yet. Is there anyone can help for this?
The text was updated successfully, but these errors were encountered: