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",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,7 +1,11 @@
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { readFileSync } from 'fs';
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({
plugins: [cssInjectedByJsPlugin()],
resolve: {
@@ -19,6 +23,7 @@ export default defineConfig({
rollupOptions: {
output: {
exports: 'named',
banner,
},
},
sourcemap: false,