add build vite plugins
This commit is contained in:
38
packages/vite/package.json
Normal file
38
packages/vite/package.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@build/vite",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "rollup -c -w",
|
||||
"build": "npm run clean && rollup -c",
|
||||
"clean": "rimraf dist"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^28.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^12.1.1",
|
||||
"@types/postcss-import": "^14.0.3",
|
||||
"@types/react": "^18.3.12",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"cross-env": "^7.0.3",
|
||||
"cssnano": "^7.0.6",
|
||||
"immer": "^10.1.1",
|
||||
"nanoid": "^5.0.8",
|
||||
"postcss-import": "^16.1.0",
|
||||
"rollup": "^4.24.3",
|
||||
"rollup-plugin-dts": "^6.1.1",
|
||||
"rollup-plugin-postcss": "^4.0.2",
|
||||
"typescript": "^5.6.3",
|
||||
"vite": "^5.4.6"
|
||||
}
|
||||
}
|
||||
33
packages/vite/rollup.config.js
Normal file
33
packages/vite/rollup.config.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import { dts } from 'rollup-plugin-dts';
|
||||
|
||||
const entrys = ['index'];
|
||||
/**
|
||||
* @type {import('rollup').RollupOptions[]}
|
||||
*/
|
||||
const configs = entrys.map((entry) => ({
|
||||
input: `./src/${entry}.ts`, // 修改输入文件为 TypeScript 文件
|
||||
output: {
|
||||
file: `./dist/${entry}.js`,
|
||||
format: 'es', // 输出格式为 ES Module
|
||||
},
|
||||
plugins: [
|
||||
resolve({ browser: false }),
|
||||
commonjs(),
|
||||
typescript({
|
||||
tsconfig: './tsconfig.json',
|
||||
}),
|
||||
],
|
||||
}));
|
||||
const dtsConfigs = {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
file: './dist/index.d.ts',
|
||||
format: 'es',
|
||||
},
|
||||
plugins: [dts()],
|
||||
};
|
||||
|
||||
export default [...configs, dtsConfigs];
|
||||
17
packages/vite/src/index.ts
Normal file
17
packages/vite/src/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
*
|
||||
* @param isDev
|
||||
* @param scriptStr <script defer src="https://umami.xiongxiao.me/script.js" data-website-id="aeea5ee5-df79-4e78-8c0d-a9f26db23695"></script>
|
||||
* @returns
|
||||
*/
|
||||
export const unamiPlugin = (scriptStr: string, isDev = false) => {
|
||||
return {
|
||||
name: 'html-transform',
|
||||
transformIndexHtml(html: string) {
|
||||
if (isDev) {
|
||||
return html;
|
||||
}
|
||||
return html.replace('</head>', `${scriptStr}</head>`);
|
||||
},
|
||||
};
|
||||
};
|
||||
37
packages/vite/tsconfig.json
Normal file
37
packages/vite/tsconfig.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": [
|
||||
"ES2020",
|
||||
"DOM",
|
||||
"DOM.Iterable"
|
||||
],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"declaration": false,
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"baseUrl": "./",
|
||||
"types": [],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user