Skip to content

Commit c3c775b

Browse files
Merge pull request #144 from linked-planet/dev
Update package.json to include bundler-plugins in files and exports. …
2 parents dde86ec + 89ca8d8 commit c3c775b

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

bundler_plugins/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// the .js extension is necessary because the bundler plugins are not typescript files
2+
// and we need to use the .js extension to import them as esm modules
3+
import viteAppendCssPlugin from "./vite-append-css-plugin.js"
4+
import { postcssClassPrefixerPlugin } from "./postcss_prefix_classname-plugin.js"
5+
import rollupClassPrefixerPlugin from "./rollup_class_prefixer-plugin.js"
6+
7+
export {
8+
viteAppendCssPlugin,
9+
postcssClassPrefixerPlugin,
10+
rollupClassPrefixerPlugin,
11+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { Plugin } from "vite"
2+
import { readFile } from "node:fs/promises"
3+
import { extname } from "node:path"
4+
5+
export interface AppendCSSOptions {
6+
/** Path to external file to include */
7+
files: string[]
8+
}
9+
10+
/**
11+
* Vite plugin that appends content of a specified file to all CSS assets in the bundle.
12+
* @param options - Plugin options containing the path to the extra file.
13+
* @returns Vite plugin object
14+
*/
15+
export default function viteAppendCssPlugin(options: AppendCSSOptions): Plugin {
16+
return {
17+
name: "append-css",
18+
enforce: "post",
19+
async generateBundle(_options, bundle) {
20+
for (const file of options.files) {
21+
const extra = await readFile(file, "utf-8")
22+
for (const [fileName, asset] of Object.entries(bundle)) {
23+
if (
24+
asset.type === "asset" &&
25+
extname(fileName) === ".css"
26+
) {
27+
const original = asset.source
28+
asset.source =
29+
typeof original === "string"
30+
? `${original}\n${extra}`
31+
: `${original.toString()}\n${extra}`
32+
console.log(
33+
"\x1b[33m%s\x1b[0m",
34+
`\n[append-css] - Appended ${file} to ${fileName}`,
35+
)
36+
}
37+
}
38+
}
39+
},
40+
}
41+
}

library/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "./styles.css"
2-
31
export * from "./components"
42
export type { DynamicFormTypes } from "./components"
53
export type { DnDTypes } from "./components"

library/src/styles.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
"module": "dist/index.js",
1313
"type": "module",
1414
"files": [
15-
"dist"
15+
"dist",
16+
"dist/bundler-plugins"
1617
],
1718
"types": "./dist/index.d.ts",
18-
"style": [
19-
"dist/styles.css",
20-
"dist/tailwindcss.css",
21-
"dist/tailwindcss-important.css"
22-
],
19+
"exports": {
20+
".": "./dist/index.js",
21+
"./*": "./dist/**/*.js",
22+
"./bundler-plugins": "./dist/bundler-plugins/index.js",
23+
"./bundler-plugins/*": "./dist/bundler-plugins/*.js"
24+
},
2325
"scripts": {
2426
"build:lib": "tsc --noEmit -p tsconfig.lib.json && vitest run && vite build -c vite.config.lib.ts && npm run messages:compile && cp -r ./twThemes dist && npm run tsc:plugin",
2527
"build:sc": "node ./showcase/copySources.js && tsc --noEmit && vite build -c vite.config.showcase.ts && node ./showcase/copyIndexTo404.js",
@@ -44,7 +46,7 @@
4446
"bcheck:lib": "biome check --apply ./library/**/*",
4547
"bformat:sc": "biome format ./showcase/**/*",
4648
"blint:sc": "biome lint ./showcase/**/*",
47-
"tsc:plugin": "tsc --moduleResolution bundler --module esnext --outDir dist/bundler-plugins --declaration bundler_plugins/rollup_class_prefixer-plugin.ts bundler_plugins/postcss_prefix_classname-plugin.ts"
49+
"tsc:plugin": "tsc --moduleResolution bundler --module esnext --outDir dist/bundler-plugins --declaration bundler_plugins/rollup_class_prefixer-plugin.ts bundler_plugins/postcss_prefix_classname-plugin.ts bundler_plugins/vite-append-css-plugin.ts bundler_plugins/index.ts"
4850
},
4951
"sideEffects": false,
5052
"author": "Markus Toepfer",
@@ -152,7 +154,7 @@
152154
"tailwindcss": "^4.0.3",
153155
"typescript": "^5.8.3",
154156
"typescript-plugin-css-modules": "^5.1.0",
155-
"vite": "^6.3.1",
157+
"vite": "^6.3.2",
156158
"vite-plugin-dts": "^4.5.3",
157159
"vitest": "^3.1.1"
158160
},

0 commit comments

Comments
 (0)