-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
HtmlWebpackPlugin inject html/variables/etc #22
Comments
so far this is a solution that works ... but hackkkkkky ... in webpack.config in root-config, set window.endpoints inside html plugin ...
webpack.config.js
in webpack.config in app1, pass endpoints as customProps webpack.config.js
grab endpoints inside of the mount lifecycle and set window.endpoints (if not set, as all front end services will be running this logic) org-app1.tsx
this works for standalone and for deployed to environment ... not ideal but works, as all apps can get host endpoints from window.endpoints let me know if there is or can or will be an easier way :D |
update: this has 1 flaw so far, when trying to use redux toolkit query, when trying to setup If |
update:
https://github.com/single-spa/create-single-spa/blob/main/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js#L126 can there be a feature request for |
any update on this? |
bump @filoxo |
a temporary solution that seems to be working
this now unlocks the capability to have a custom html file used for the generation of the standalone component, other stuff can be added, like pattern library classes, themes, etc. Currently all documentation only allows all this stuff to work via root-config, and not in standalone mode for individual components. |
Sorry about the lack of response, I hadn't seen this ping. I wonder if webpack-merge's mergeWithCustomize can be used to clean this up a little bit: const { mergeWithCustomize, unique } = require('webpack-merge');
const singleSpaDefaults = require('webpack-config-single-spa');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = mergeWithCustomize({
customizeArray: unique(
'plugins',
['HtmlWebpackPlugin'],
(plugin) => plugin.constructor && plugin.constructor.name
),
}); which I've used in an example repo that I maintain here: https://github.com/filoxo/single-spa-example-rxjs-shared-state/blob/main/packages/root-config/webpack.config.js#L5-L11 except that that example doesn't make use of standalone mode. Maybe that could work for this case still though? I think your solution should be taken and made into an org-specific single-spa-webpack-config package to share across your applications. Its basically just taking our config and wrapping with your org's needs/opinions/rules. |
Thanks for the reply! I will give that approach a try ... |
I'm wanting to use standalone mode in a similar fashion, and I can't get it working with either mergeWithCustomize or instantiating an extended HtmlWebpackPlugin class. I'd vote for going with the options param for HtmlWebpackPlugin, similar to standaloneOptions. And/or the ability to expand to be not limited to 1 html file that gets generated with the various import-map etc |
I disagree with expanding the configuration API... mostly because where does it end? The base single-spa-webpack-config includes other plugins too so if we allow passing through all options for one plugin, we'd probably have to allow all options for all plugins. This is why I prefer webpack-merge: you can extend the inner parts of the config without it having to create a top-level API for overrides. Alternatively, using |
is there a way currently to inject something like ... html or templateParameters into the HtmlWebpackPlugin ...
my use case is ... the root-config is setting
API_ENDPOINTS
on the window for all other micro services to use, works great, they have access to it and everything ... problem is standalone development ... they can't get the endpoint as its not on the windowor even a feature to set window variables?
https://github.com/single-spa/create-single-spa/blob/main/packages/webpack-config-single-spa/lib/webpack-config-single-spa.js#L126
might have to change the design to pass it as a customProp as that is supported in the standalone-single-spa-webpack-plugin
EDIT: attempted this, there is no way for me to send customProps from webpack.config inside the root-config ... can do that from a non root-config, as it uses the standalone-single-spa-webpack-plugin, but in root-config, that is disabled.
https://github.com/single-spa/standalone-single-spa-webpack-plugin#customizing-the-html-file
^^ can i use teplateParamters and put it in the index file and pass to standalone-single-spa-webpack-plugin?
The text was updated successfully, but these errors were encountered: