Skip to content

Commit

Permalink
fix: 修复siteEffect 导致lib包引入样式问题
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin committed Oct 29, 2024
1 parent 37afc9a commit d42cb13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"CHANGELOG.md"
],
"sideEffects": [
"src/**/style/**",
"dist/*",
"site/*",
"es/**/style/**",
Expand Down
13 changes: 12 additions & 1 deletion site/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const publicPathMap = {
production: 'https://static.tdesign.tencent.com/react/',
};

const disableTreeShakingPlugin = (paths) => ({
name: 'disable-treeshake',
transform(code, id) {
for (const path of paths) {
if (id.includes(path)) {
return { code, map: null, moduleSideEffects: 'no-treeshake' };
}
}
},
});

export default ({ mode }) =>
defineConfig({
base: publicPathMap[mode],
Expand Down Expand Up @@ -50,5 +61,5 @@ export default ({ mode }) =>
test: {
environment: 'jsdom',
},
plugins: [react(), tdocPlugin(), VitePWA(pwaConfig)],
plugins: [react(), tdocPlugin(), VitePWA(pwaConfig), disableTreeShakingPlugin(['style/'])],
});

0 comments on commit d42cb13

Please sign in to comment.