Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
79 lines (75 loc) · 2.85 KB
/
Copy pathvite.config.ts
File metadata and controls
79 lines (75 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// =============================================================================
// vite.config.ts — stylescape-devcontainer build
// =============================================================================
//
// This package is consumed primarily as SCSS *source* (see the `exports` map
// in package.json). This Vite build exists only to emit the convenience
// compiled stylesheets:
//
// dist/css/ss.css core + theme `vite build`
// dist/css/ss.min.css `NO_EMPTY=1 MINIFY=1 vite build`
//
// The `build` script runs both passes; only the first may empty `dist/`.
// `src/ts/entries/core.ts` is a side-effect entry that imports the SCSS so
// Vite's library build extracts the CSS bundle.
//
// The theme sits ON TOP of stylescape core, so the Sass NodePackageImporter
// must be registered for `pkg:stylescape/scss` to resolve.
// =============================================================================
import { defineConfig } from "vite";
import { fileURLToPath } from "node:url";
import { NodePackageImporter } from "sass";
import type { DeprecationOrId } from "sass";
/**
* Core still calls `map-get` and the old `if()`, and loads a couple of files
* with `@import`. They are its warnings to fix, not this package's.
*/
const SILENCED: DeprecationOrId[] = [
"global-builtin",
"if-function",
"import",
];
export default defineConfig(() => {
const minify = process.env.MINIFY === "1";
return {
// No PostCSS step — keep the build hermetic and skip config-file
// search. Consumers `@use` the SCSS source and autoprefix in their
// own pipeline.
css: {
postcss: {},
preprocessorOptions: {
scss: {
importers: [new NodePackageImporter()],
quietDeps: true,
silenceDeprecations: SILENCED,
},
},
},
build: {
outDir: "dist",
emptyOutDir: process.env.NO_EMPTY !== "1",
cssMinify: minify,
lib: {
entry: fileURLToPath(
new URL("./src/ts/entries/core.ts", import.meta.url),
),
formats: ["es" as const],
fileName: () => "js/stylescape-devcontainer.js",
},
rollupOptions: {
output: {
assetFileNames: (asset: {
names?: string[];
name?: string;
}) => {
const name = asset.names?.[0] ?? asset.name ?? "";
if (name.endsWith(".css")) {
return minify ? "css/ss.min.css" : "css/ss.css";
}
return "assets/[name][extname]";
},
},
},
},
};
});