build(widget): 添加版本号并配置构建banner

在package.json中添加版本号字段,并在vite配置中读取版本号生成构建banner,用于标识构建产物版本
This commit is contained in:
anghunk
2026-01-21 11:52:45 +08:00
parent c0bf1ba066
commit 5c6f156b80
3 changed files with 7 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
{ {
"name": "widget", "name": "widget",
"version": "0.0.1",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {

View File

@@ -1,7 +1,11 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import { resolve } from 'path'; import { resolve } from 'path';
import { readFileSync } from 'fs';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'; import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
const banner = `/*! CWDComments widget v${pkg.version} */`;
export default defineConfig({ export default defineConfig({
plugins: [cssInjectedByJsPlugin()], plugins: [cssInjectedByJsPlugin()],
resolve: { resolve: {
@@ -19,6 +23,7 @@ export default defineConfig({
rollupOptions: { rollupOptions: {
output: { output: {
exports: 'named', exports: 'named',
banner,
}, },
}, },
sourcemap: false, sourcemap: false,