@basmilius/vite-preset 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/composeLibrary.d.ts +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +12 -0
- package/dist/libraries.d.ts +5 -0
- package/dist/preset.d.ts +11 -0
- package/package.json +57 -0
- package/src/composeLibrary.ts +71 -0
- package/src/deps.d.ts +3 -0
- package/src/index.ts +12 -0
- package/src/libraries.ts +14 -0
- package/src/preset.ts +109 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<a href="https://bas.dev" target="_blank" rel="noopener">
|
|
2
|
+
<img src="https://bmcdn.nl/assets/branding/logo.svg" alt="Bas-logo" height="48"/>
|
|
3
|
+
</a>
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# `@basmilius/vite-preset`
|
|
8
|
+
|
|
9
|
+
Contains presets for [Vite](https://vite.dev) and [Vue](https://vuejs.org).
|
|
10
|
+
|
|
11
|
+
## ⭐️ Prerequisites
|
|
12
|
+
|
|
13
|
+
- Bun >= 1.2.11
|
|
14
|
+
- Node >= 23
|
|
15
|
+
|
|
16
|
+
## 🚀 Getting started
|
|
17
|
+
|
|
18
|
+
1. Run `bun install` in the root of the project.
|
|
19
|
+
2. Run `bun --cwd packages/vite-preset build` to build the project.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
type ComposePlugin = () => Plugin;
|
|
3
|
+
type PathGenerator = (name: string) => string;
|
|
4
|
+
type Options = {
|
|
5
|
+
readonly name: string
|
|
6
|
+
readonly alias: string
|
|
7
|
+
readonly sourcesPathGenerator?: PathGenerator
|
|
8
|
+
readonly tsAliasPathGenerator?: PathGenerator
|
|
9
|
+
};
|
|
10
|
+
declare const _default: (options: Options) => ComposePlugin;
|
|
11
|
+
export default _default;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{existsSync as g,readFileSync as h,writeFileSync as y}from"node:fs";import{join as u,relative as b,resolve as P}from"node:path";import{searchForWorkspaceRoot as x}from"vite";var n=process.cwd(),N=x(n),f=u(b(n,N),"node_modules"),O=(e)=>P(n,`${f}/${e}/src`),S=(e)=>`${f}/${e}/src/*`,a=(e)=>{let t=e.sourcesPathGenerator??O,r=e.tsAliasPathGenerator??S,i=t(e.name);return()=>({name:e.name,config:()=>({optimizeDeps:{exclude:[e.name]},resolve:{alias:{[e.name]:i,[e.alias]:i}},server:{fs:{allow:[i]}}}),configResolved(c){let o=u(c.root,"tsconfig.json");if(!g(o))c.logger.error(`[${e.name}] A tsconfig.json is required for this library. Please create one.`),process.exit(1);let m=`${e.alias}/*`,d=h(o,{encoding:"utf-8"}),s=JSON.parse(d);if(s.compilerOptions.paths??={},m in s.compilerOptions.paths)return;s.compilerOptions.paths[m]=[r(e.name)],y(o,JSON.stringify(s,null,4),{encoding:"utf-8"})}})};import{resolve as L}from"node:path";import{camelCase as v,kebabCase as G}from"change-case";import{patchCssModules as C}from"vite-css-modules";import{searchForWorkspaceRoot as D}from"vite";import p from"css-class-generator";import A from"@laynezh/vite-plugin-lib-assets";import _ from"vite-plugin-dts";var l=[],j=(e)=>{function t(r){if(r.startsWith("i__const_"))r=r.substring(9),r=r.substring(0,r.length-2);if(e.cssModules?.classNames==="camel")return v(r);if(e.cssModules?.classNames==="kebab")return G(r);if(l.includes(r))return p(l.indexOf(r));return p(l.push(r)-1)}return{name:"@basmilius/vite-preset",config:()=>({build:{assetsInlineLimit:0,cssMinify:"lightningcss",minify:"esbuild",rollupOptions:{output:{assetFileNames:e.fileNames==="actual"||e.isLibrary?void 0:"[hash].[ext]",chunkFileNames:e.fileNames==="actual"||e.isLibrary?void 0:"[hash].js",entryFileNames:e.fileNames==="actual"||e.isLibrary?void 0:"[hash].js",compact:!e.isLibrary,minifyInternalExports:!0}}},css:{preprocessorMaxWorkers:!0,preprocessorOptions:{scss:{api:"modern-compiler"}},modules:{generateScopedName:e.cssModules?.generateScopedName??t}},json:{stringify:!0},resolve:{alias:{"@":L(process.cwd(),"./src")},extensions:[".js",".ts",".json",".vue"]},server:{fs:{allow:[D(process.cwd())]}}})}},k=(e={})=>[C(),j(e),e.isLibrary&&A({limit:0,name:"[contenthash:8].[ext]"}),e.isLibrary&&_({cleanVueFileName:!1})];var F=a({name:"@flux-ui/components",alias:"$flux"}),M=a({name:"@flux-ui/dashboard",alias:"$fluxDashboard"});export{k as preset,M as fluxDashboard,F as flux,a as composeLibrary};
|
|
2
|
+
|
|
3
|
+
//# debugId=BEC55BC0F116414B64756E2164756E21
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/composeLibrary.ts", "../src/preset.ts", "../src/libraries.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join, relative, resolve } from 'node:path';\nimport type { Plugin, UserConfig } from 'vite';\nimport { searchForWorkspaceRoot } from 'vite';\n\ntype ComposePlugin = () => Plugin;\ntype PathGenerator = (name: string) => string;\n\ntype Options = {\n readonly name: string;\n readonly alias: string;\n readonly sourcesPathGenerator?: PathGenerator;\n readonly tsAliasPathGenerator?: PathGenerator;\n};\n\nconst WORKING_DIR = process.cwd();\nconst WORKSPACE_ROOT = searchForWorkspaceRoot(WORKING_DIR);\nconst WORKSPACE_NODE_MODULES = join(relative(WORKING_DIR, WORKSPACE_ROOT), 'node_modules');\n\nconst defaultSourcesPathGenerator: PathGenerator = name => resolve(WORKING_DIR, `${WORKSPACE_NODE_MODULES}/${name}/src`);\nconst defaultTsAliasPathGenerator: PathGenerator = name => `${WORKSPACE_NODE_MODULES}/${name}/src/*`;\n\nexport default (options: Options): ComposePlugin => {\n const sourcesPathGenerator = options.sourcesPathGenerator ?? defaultSourcesPathGenerator;\n const tsAliasPathGenerator = options.tsAliasPathGenerator ?? defaultTsAliasPathGenerator;\n\n const src = sourcesPathGenerator(options.name);\n\n return (): Plugin => ({\n name: options.name,\n\n config: (): UserConfig => ({\n optimizeDeps: {\n exclude: [options.name]\n },\n resolve: {\n alias: {\n [options.name]: src,\n [options.alias]: src\n }\n },\n server: {\n fs: {\n allow: [src]\n }\n }\n }),\n\n configResolved(config): void {\n const tsconfigPath = join(config.root, 'tsconfig.json');\n\n if (!existsSync(tsconfigPath)) {\n config.logger.error(`[${options.name}] A tsconfig.json is required for this library. Please create one.`);\n process.exit(1);\n }\n\n const key = `${options.alias}/*`;\n const tsconfigData = readFileSync(tsconfigPath, {encoding: 'utf-8'});\n const tsconfig = JSON.parse(tsconfigData);\n tsconfig.compilerOptions.paths ??= {};\n\n if (key in tsconfig.compilerOptions.paths) {\n return;\n }\n\n tsconfig.compilerOptions.paths[key] = [tsAliasPathGenerator(options.name)];\n\n writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4), {encoding: 'utf-8'});\n }\n });\n};\n",
|
|
6
|
+
"import { resolve } from 'node:path';\nimport { camelCase, kebabCase } from 'change-case';\nimport { patchCssModules } from 'vite-css-modules';\nimport type { Plugin } from 'vite';\nimport { searchForWorkspaceRoot } from 'vite';\nimport className from 'css-class-generator';\nimport libAssets from '@laynezh/vite-plugin-lib-assets';\nimport libDts from 'vite-plugin-dts';\n\nconst VISITED_CLASSES: string[] = [];\n\ntype Options = {\n readonly cssModules?: {\n readonly classNames?: 'mangled' | 'camel' | 'kebab';\n readonly generateScopedName?: (name: string, filename: string, css: string) => string;\n };\n readonly fileNames?: 'hashes' | 'actual';\n readonly isLibrary?: boolean;\n};\n\nconst presets = (options: Options): Plugin => {\n function generateScopedName(name: string): string {\n if (name.startsWith('i__const_')) {\n name = name.substring(9);\n name = name.substring(0, name.length - 2);\n }\n\n if (options.cssModules?.classNames === 'camel') {\n return camelCase(name);\n }\n\n if (options.cssModules?.classNames === 'kebab') {\n return kebabCase(name);\n }\n\n if (VISITED_CLASSES.includes(name)) {\n return className(VISITED_CLASSES.indexOf(name));\n }\n\n return className(VISITED_CLASSES.push(name) - 1);\n }\n\n return {\n name: '@basmilius/vite-preset',\n\n config: () => ({\n build: {\n assetsInlineLimit: 0,\n cssMinify: 'lightningcss',\n minify: 'esbuild',\n rollupOptions: {\n output: {\n assetFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].[ext]',\n chunkFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].js',\n entryFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].js',\n compact: !options.isLibrary,\n minifyInternalExports: true\n }\n }\n },\n css: {\n preprocessorMaxWorkers: true,\n preprocessorOptions: {\n scss: {\n api: 'modern-compiler'\n }\n },\n modules: {\n generateScopedName: options.cssModules?.generateScopedName ?? generateScopedName\n }\n },\n json: {\n stringify: true\n },\n resolve: {\n alias: {\n '@': resolve(process.cwd(), './src')\n },\n extensions: [\n '.js',\n '.ts',\n '.json',\n '.vue'\n ]\n },\n server: {\n fs: {\n allow: [\n searchForWorkspaceRoot(process.cwd())\n ]\n }\n }\n })\n };\n};\n\nexport default (options: Options = {}): Plugin[] => [\n patchCssModules(),\n presets(options),\n\n options.isLibrary && libAssets({\n limit: 0,\n name: '[contenthash:8].[ext]'\n }),\n\n options.isLibrary && libDts({\n cleanVueFileName: false\n })\n] satisfies Plugin[];\n",
|
|
7
|
+
"import type { Plugin } from 'vite';\nimport composeLibrary from './composeLibrary';\n\ntype LibraryPlugin = () => Plugin;\n\nexport const flux: LibraryPlugin = composeLibrary({\n name: '@flux-ui/components',\n alias: '$flux'\n});\n\nexport const fluxDashboard: LibraryPlugin = composeLibrary({\n name: '@flux-ui/dashboard',\n alias: '$fluxDashboard'\n});\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": "AAAA,qBAAS,kBAAY,mBAAc,gBACnC,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,EACtB,CAAC,CACL,ECvGO,IAAM,EAAsB,EAAe,CAC9C,KAAM,sBACN,MAAO,OACX,CAAC,EAEY,EAA+B,EAAe,CACvD,KAAM,qBACN,MAAO,gBACX,CAAC",
|
|
10
|
+
"debugId": "BEC55BC0F116414B64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
type Options = {
|
|
3
|
+
readonly cssModules?: {
|
|
4
|
+
readonly classNames?: "mangled" | "camel" | "kebab"
|
|
5
|
+
readonly generateScopedName?: (name: string, filename: string, css: string) => string
|
|
6
|
+
}
|
|
7
|
+
readonly fileNames?: "hashes" | "actual"
|
|
8
|
+
readonly isLibrary?: boolean
|
|
9
|
+
};
|
|
10
|
+
declare const _default: (options?: Options) => Plugin[];
|
|
11
|
+
export default _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@basmilius/vite-preset",
|
|
3
|
+
"description": "Commonly used presets used in Vite + Vue setups.",
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/basmilius",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Bas Milius",
|
|
10
|
+
"email": "bas@mili.us",
|
|
11
|
+
"url": "https://bas.dev"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/basmilius/packages.git",
|
|
16
|
+
"directory": "packages/vite-preset"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"build",
|
|
20
|
+
"vite",
|
|
21
|
+
"preset",
|
|
22
|
+
"vue"
|
|
23
|
+
],
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"provenance": true
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "bun -b build.ts"
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"typings": "./dist/index.d.ts",
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"default": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@laynezh/vite-plugin-lib-assets": "^1.1.0",
|
|
47
|
+
"change-case": "^5.4.4",
|
|
48
|
+
"css-class-generator": "^2.0.0",
|
|
49
|
+
"lightningcss": "^1.29.3",
|
|
50
|
+
"vite-css-modules": "^1.8.6",
|
|
51
|
+
"vite-plugin-dts": "^4.5.3"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@basmilius/tools": "2.0.0",
|
|
55
|
+
"vite": "^6.3.3"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, relative, resolve } from 'node:path';
|
|
3
|
+
import type { Plugin, UserConfig } from 'vite';
|
|
4
|
+
import { searchForWorkspaceRoot } from 'vite';
|
|
5
|
+
|
|
6
|
+
type ComposePlugin = () => Plugin;
|
|
7
|
+
type PathGenerator = (name: string) => string;
|
|
8
|
+
|
|
9
|
+
type Options = {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly alias: string;
|
|
12
|
+
readonly sourcesPathGenerator?: PathGenerator;
|
|
13
|
+
readonly tsAliasPathGenerator?: PathGenerator;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const WORKING_DIR = process.cwd();
|
|
17
|
+
const WORKSPACE_ROOT = searchForWorkspaceRoot(WORKING_DIR);
|
|
18
|
+
const WORKSPACE_NODE_MODULES = join(relative(WORKING_DIR, WORKSPACE_ROOT), 'node_modules');
|
|
19
|
+
|
|
20
|
+
const defaultSourcesPathGenerator: PathGenerator = name => resolve(WORKING_DIR, `${WORKSPACE_NODE_MODULES}/${name}/src`);
|
|
21
|
+
const defaultTsAliasPathGenerator: PathGenerator = name => `${WORKSPACE_NODE_MODULES}/${name}/src/*`;
|
|
22
|
+
|
|
23
|
+
export default (options: Options): ComposePlugin => {
|
|
24
|
+
const sourcesPathGenerator = options.sourcesPathGenerator ?? defaultSourcesPathGenerator;
|
|
25
|
+
const tsAliasPathGenerator = options.tsAliasPathGenerator ?? defaultTsAliasPathGenerator;
|
|
26
|
+
|
|
27
|
+
const src = sourcesPathGenerator(options.name);
|
|
28
|
+
|
|
29
|
+
return (): Plugin => ({
|
|
30
|
+
name: options.name,
|
|
31
|
+
|
|
32
|
+
config: (): UserConfig => ({
|
|
33
|
+
optimizeDeps: {
|
|
34
|
+
exclude: [options.name]
|
|
35
|
+
},
|
|
36
|
+
resolve: {
|
|
37
|
+
alias: {
|
|
38
|
+
[options.name]: src,
|
|
39
|
+
[options.alias]: src
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
server: {
|
|
43
|
+
fs: {
|
|
44
|
+
allow: [src]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
|
|
49
|
+
configResolved(config): void {
|
|
50
|
+
const tsconfigPath = join(config.root, 'tsconfig.json');
|
|
51
|
+
|
|
52
|
+
if (!existsSync(tsconfigPath)) {
|
|
53
|
+
config.logger.error(`[${options.name}] A tsconfig.json is required for this library. Please create one.`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const key = `${options.alias}/*`;
|
|
58
|
+
const tsconfigData = readFileSync(tsconfigPath, {encoding: 'utf-8'});
|
|
59
|
+
const tsconfig = JSON.parse(tsconfigData);
|
|
60
|
+
tsconfig.compilerOptions.paths ??= {};
|
|
61
|
+
|
|
62
|
+
if (key in tsconfig.compilerOptions.paths) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
tsconfig.compilerOptions.paths[key] = [tsAliasPathGenerator(options.name)];
|
|
67
|
+
|
|
68
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4), {encoding: 'utf-8'});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
package/src/deps.d.ts
ADDED
package/src/index.ts
ADDED
package/src/libraries.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import composeLibrary from './composeLibrary';
|
|
3
|
+
|
|
4
|
+
type LibraryPlugin = () => Plugin;
|
|
5
|
+
|
|
6
|
+
export const flux: LibraryPlugin = composeLibrary({
|
|
7
|
+
name: '@flux-ui/components',
|
|
8
|
+
alias: '$flux'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const fluxDashboard: LibraryPlugin = composeLibrary({
|
|
12
|
+
name: '@flux-ui/dashboard',
|
|
13
|
+
alias: '$fluxDashboard'
|
|
14
|
+
});
|
package/src/preset.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { camelCase, kebabCase } from 'change-case';
|
|
3
|
+
import { patchCssModules } from 'vite-css-modules';
|
|
4
|
+
import type { Plugin } from 'vite';
|
|
5
|
+
import { searchForWorkspaceRoot } from 'vite';
|
|
6
|
+
import className from 'css-class-generator';
|
|
7
|
+
import libAssets from '@laynezh/vite-plugin-lib-assets';
|
|
8
|
+
import libDts from 'vite-plugin-dts';
|
|
9
|
+
|
|
10
|
+
const VISITED_CLASSES: string[] = [];
|
|
11
|
+
|
|
12
|
+
type Options = {
|
|
13
|
+
readonly cssModules?: {
|
|
14
|
+
readonly classNames?: 'mangled' | 'camel' | 'kebab';
|
|
15
|
+
readonly generateScopedName?: (name: string, filename: string, css: string) => string;
|
|
16
|
+
};
|
|
17
|
+
readonly fileNames?: 'hashes' | 'actual';
|
|
18
|
+
readonly isLibrary?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const presets = (options: Options): Plugin => {
|
|
22
|
+
function generateScopedName(name: string): string {
|
|
23
|
+
if (name.startsWith('i__const_')) {
|
|
24
|
+
name = name.substring(9);
|
|
25
|
+
name = name.substring(0, name.length - 2);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (options.cssModules?.classNames === 'camel') {
|
|
29
|
+
return camelCase(name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (options.cssModules?.classNames === 'kebab') {
|
|
33
|
+
return kebabCase(name);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (VISITED_CLASSES.includes(name)) {
|
|
37
|
+
return className(VISITED_CLASSES.indexOf(name));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return className(VISITED_CLASSES.push(name) - 1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
name: '@basmilius/vite-preset',
|
|
45
|
+
|
|
46
|
+
config: () => ({
|
|
47
|
+
build: {
|
|
48
|
+
assetsInlineLimit: 0,
|
|
49
|
+
cssMinify: 'lightningcss',
|
|
50
|
+
minify: 'esbuild',
|
|
51
|
+
rollupOptions: {
|
|
52
|
+
output: {
|
|
53
|
+
assetFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].[ext]',
|
|
54
|
+
chunkFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].js',
|
|
55
|
+
entryFileNames: options.fileNames === 'actual' || options.isLibrary ? undefined : '[hash].js',
|
|
56
|
+
compact: !options.isLibrary,
|
|
57
|
+
minifyInternalExports: true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
css: {
|
|
62
|
+
preprocessorMaxWorkers: true,
|
|
63
|
+
preprocessorOptions: {
|
|
64
|
+
scss: {
|
|
65
|
+
api: 'modern-compiler'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
modules: {
|
|
69
|
+
generateScopedName: options.cssModules?.generateScopedName ?? generateScopedName
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
json: {
|
|
73
|
+
stringify: true
|
|
74
|
+
},
|
|
75
|
+
resolve: {
|
|
76
|
+
alias: {
|
|
77
|
+
'@': resolve(process.cwd(), './src')
|
|
78
|
+
},
|
|
79
|
+
extensions: [
|
|
80
|
+
'.js',
|
|
81
|
+
'.ts',
|
|
82
|
+
'.json',
|
|
83
|
+
'.vue'
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
server: {
|
|
87
|
+
fs: {
|
|
88
|
+
allow: [
|
|
89
|
+
searchForWorkspaceRoot(process.cwd())
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default (options: Options = {}): Plugin[] => [
|
|
98
|
+
patchCssModules(),
|
|
99
|
+
presets(options),
|
|
100
|
+
|
|
101
|
+
options.isLibrary && libAssets({
|
|
102
|
+
limit: 0,
|
|
103
|
+
name: '[contenthash:8].[ext]'
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
options.isLibrary && libDts({
|
|
107
|
+
cleanVueFileName: false
|
|
108
|
+
})
|
|
109
|
+
] satisfies Plugin[];
|