Skip to content

Commit

Permalink
build: mark component files with side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubisation committed Dec 7, 2023
1 parent 65f4f56 commit ce0228d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/components/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PluginOption, ResolvedConfig, defineConfig } from 'vite';
export const root = new URL('.', import.meta.url);

export function packageJsonTemplate(
options: { exports?: Record<string, Record<string, unknown>> } = {},
options: { exports?: Record<string, Record<string, unknown>>; sideEffects?: string[] } = {},
): PluginOption {
let viteConfig: ResolvedConfig;
return {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit ce0228d

Please sign in to comment.