diff --git a/src/components/vite.config.ts b/src/components/vite.config.ts index b58d9c0dec..566107336c 100644 --- a/src/components/vite.config.ts +++ b/src/components/vite.config.ts @@ -1,6 +1,8 @@ +import { readFileSync } from 'fs'; import { join } from 'path'; import { cli } from '@custom-elements-manifest/analyzer/cli'; +import * as glob from 'glob'; import * as sass from 'sass'; import { ConfigEnv, @@ -42,6 +44,16 @@ export default defineConfig((config) => style: './typography.css', }, }, + sideEffects: glob + .sync('**/*.ts', { cwd: packageRoot, dotRelative: true }) + .map((file) => ({ + file, + content: readFileSync(new URL(file, packageRoot), 'utf8'), + })) + .filter((f) => f.content.includes(`@customElement('sbb-`)) + .map((f) => f.file.replace(/[\w-]+\.ts$/, 'index.js')) + .filter((v, i, a) => a.indexOf(v) === i) + .sort(), }), copyAssets(['_index.scss', 'core/styles/**/*.scss']), typography(), diff --git a/vite.config.ts b/vite.config.ts index e9b1867be7..c690a00d73 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,7 +8,7 @@ import { PluginOption, ResolvedConfig, defineConfig } from 'vite'; export const root = new URL('.', import.meta.url); export function packageJsonTemplate( - options: { exports?: Record> } = {}, + options: { exports?: Record>; sideEffects?: string[] } = {}, ): PluginOption { let viteConfig: ResolvedConfig; return { @@ -59,6 +59,10 @@ export function packageJsonTemplate( packageJson.exports = options.exports; } + if (options.sideEffects) { + packageJson.sideEffects = options.sideEffects; + } + this.emitFile({ type: 'asset', fileName: 'package.json',