Skip to content

Commit b76e800

Browse files
committed
Add option to inject styles into window - for hf-inj-react bundling
1 parent 38f92c3 commit b76e800

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/react-scripts/config/webpack.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,21 @@ module.exports = function (webpackEnv) {
140140
// common function to get style loaders
141141
const getStyleLoaders = (cssOptions, preProcessor) => {
142142
const loaders = [
143-
isEnvDevelopment && require.resolve('style-loader'),
143+
isEnvDevelopment && {
144+
loader: require.resolve('style-loader'),
145+
options: process.env.REACT_APP_HF_INJECT_STYLES ? {
146+
injectType: 'singletonStyleTag',
147+
insert: function addToWindowObject(element) {
148+
149+
const _window = typeof window !== 'undefined' ? window : {}
150+
if (!_window.hfBundleStyles) {
151+
_window.hfBundleStyles = []
152+
}
153+
element.classList.add('linaria-style')
154+
_window.hfBundleStyles.push(element)
155+
}
156+
} : {},
157+
},
144158
isEnvProduction && {
145159
loader: MiniCssExtractPlugin.loader,
146160
// css is located in `static/css`, use '../../' to locate index.html folder

0 commit comments

Comments
 (0)