Skip to content

Commit

Permalink
Merge pull request #190 from BouyguesTelecom/fix/script-css
Browse files Browse the repository at this point in the history
Fix script hash class in css
  • Loading branch information
JulienMora authored Nov 7, 2024
2 parents 4deea2d + 477fcac commit 0e655cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/react-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const root = ReactDOM.createRoot(rootElement)

root.render(
<React.StrictMode>
<TrilogyProviderStyled>
<TrilogyProviderStyled theme='mangled'>
<HashRouter>
<Router />
</HashRouter>
Expand Down
11 changes: 5 additions & 6 deletions packages/styles/config/plugins/vite-plugin-mangler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ export const cssPlugin = () => {
name: 'css-transform',
transform(src: string, id: string) {
if (/mangled\.(scss)$/.test(id)) {
src.replace(/(\.[a-z][_\-0-9a-z]*)(?=[^\{]*{)/gi, (match) => {
return `${match}__${HASH}`
})
return src
.replace(/(\.[a-z][_\-0-9a-z]*)(?=[^\{]*{)/gi, (match) => {
return `${match}__${HASH}`
})

return src.replace(/url\(\s*['"]?[^"')]*$/i, (match) => {
return match.split('_')[0]
})
.replace(/(url\(["']?.*?)(__[\w]+)(.*?["']?\))/g, '$1$3')
}
},
}
Expand Down

0 comments on commit 0e655cc

Please sign in to comment.