chore: improve build scripts; change esm dir

This commit is contained in:
Simon
2025-12-16 19:45:40 +08:00
parent 3082843810
commit 2fee2d5ea3
10 changed files with 41 additions and 33 deletions

View File

@@ -25,7 +25,7 @@ jobs:
run: npm ci
- name: Build demo
run: npm run build
run: npm run build:website
- name: Setup Pages
uses: actions/configure-pages@v5

View File

@@ -29,7 +29,7 @@ jobs:
run: npm ci
- name: Build
run: npm run build
run: npm run build:libs
- name: Publish all public packages
run: npm publish --workspaces --access public

View File

@@ -19,6 +19,8 @@ And other internal packages:
```bash
npm start # Start website dev server
npm run build # Build all packages
npm run build:libs # Build all libraries
npm run build:website # Build the website
npm run lint # ESLint with TypeScript strict rules
```

16
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "root",
"version": "0.0.10",
"version": "0.0.11",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "root",
"version": "0.0.10",
"version": "0.0.11",
"license": "MIT",
"workspaces": [
"packages/page-controller",
@@ -7184,23 +7184,23 @@
}
},
"packages/page-agent": {
"version": "0.0.10",
"version": "0.0.11",
"license": "MIT",
"dependencies": {
"@page-agent/page-controller": "0.0.10",
"@page-agent/ui": "0.0.10",
"@page-agent/page-controller": "0.0.11",
"@page-agent/ui": "0.0.11",
"chalk": "^5.6.2",
"zod": "^4.2.0"
}
},
"packages/page-controller": {
"name": "@page-agent/page-controller",
"version": "0.0.10",
"version": "0.0.11",
"license": "MIT"
},
"packages/ui": {
"name": "@page-agent/ui",
"version": "0.0.10",
"version": "0.0.11",
"license": "MIT",
"dependencies": {
"ai-motion": "^0.4.7"
@@ -7208,7 +7208,7 @@
},
"packages/website": {
"name": "@page-agent/website",
"version": "0.0.10",
"version": "0.0.11",
"devDependencies": {
"@tailwindcss/vite": "^4.1.18",
"@types/react": "^19.2.2",

View File

@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"workspaces": [
"packages/page-controller",
@@ -23,7 +23,9 @@
},
"scripts": {
"start": "npm run dev --workspace=@page-agent/website",
"build": "npm run build --workspaces --if-present",
"build:website": "npm run build:website --workspace=@page-agent/website",
"build:libs": "npm run build --workspaces --if-present",
"build": "npm run build:libs && npm run build:website",
"dev:umd": "npm run dev:umd --workspace=page-agent",
"version": "node scripts/sync-version.js",
"lint": "eslint .",

View File

@@ -1,16 +1,16 @@
{
"name": "page-agent",
"private": false,
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"main": "./dist/lib/page-agent.js",
"module": "./dist/lib/page-agent.js",
"types": "./dist/lib/PageAgent.d.ts",
"main": "./dist/esm/page-agent.js",
"module": "./dist/esm/page-agent.js",
"types": "./dist/esm/PageAgent.d.ts",
"exports": {
".": {
"types": "./dist/lib/PageAgent.d.ts",
"import": "./dist/lib/page-agent.js",
"default": "./dist/lib/page-agent.js"
"types": "./dist/esm/PageAgent.d.ts",
"import": "./dist/esm/page-agent.js",
"default": "./dist/esm/page-agent.js"
}
},
"files": [
@@ -37,7 +37,7 @@
},
"homepage": "https://alibaba.github.io/page-agent/",
"scripts": {
"build": "MODE=lib vite build && MODE=umd vite build",
"build": "vite build && MODE=umd vite build",
"serve": "npx serve dist/umd -p 5173",
"dev:umd": "concurrently \"MODE=umd vite build --watch\" \"npm run serve\"",
"prepublishOnly": "node -e \"const fs=require('fs');['README.md','LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
@@ -46,7 +46,7 @@
"dependencies": {
"chalk": "^5.6.2",
"zod": "^4.2.0",
"@page-agent/page-controller": "0.0.10",
"@page-agent/ui": "0.0.10"
"@page-agent/page-controller": "0.0.11",
"@page-agent/ui": "0.0.11"
}
}

View File

@@ -11,14 +11,13 @@ import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
const __dirname = dirname(fileURLToPath(import.meta.url))
// ============================================================================
// Library Config (ES Module for NPM Package)
// ES Module for NPM Package
// ============================================================================
/** @type {import('vite').UserConfig} */
const libConfig = {
const esmConfig = {
clearScreen: false,
plugins: [
dts({ tsconfigPath: './tsconfig.dts.json', bundleTypes: true }),
// dts({ tsconfigPath: './tsconfig.json', bundleTypes: true, compilerOptions: { paths: {} } }),
cssInjectedByJsPlugin({ relativeCSSInjection: true }),
],
publicDir: false,
@@ -32,7 +31,7 @@ const libConfig = {
fileName: 'page-agent',
formats: ['es'],
},
outDir: resolve(__dirname, 'dist', 'lib'),
outDir: resolve(__dirname, 'dist', 'esm'),
rollupOptions: {
external: [
'chalk',
@@ -51,7 +50,7 @@ const libConfig = {
}
// ============================================================================
// UMD Config (Browser Bundle for CDN)
// UMD Bundle for CDN
// - alias all local packages so that they can be build in
// - no external
// - no d.ts. dts does not work with monorepo aliasing
@@ -77,6 +76,11 @@ const umdConfig = {
formats: ['umd'],
},
outDir: resolve(__dirname, 'dist', 'umd'),
rollupOptions: {
output: {
entryFileNames: 'page-agent.js', // 强制指定完整文件名
},
},
cssCodeSplit: true,
},
define: {
@@ -88,13 +92,13 @@ const umdConfig = {
const MODE = process.env.MODE
console.log(chalk.cyan(`📦 Build mode: ${chalk.bold(MODE || 'lib')}`))
console.log(chalk.cyan(`📦 Build mode: ${chalk.bold(MODE || 'esm')}`))
let config
if (MODE === 'umd') {
config = umdConfig
} else {
config = libConfig
config = esmConfig
}
export default defineConfig(config)

View File

@@ -1,6 +1,6 @@
{
"name": "@page-agent/page-controller",
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"main": "./dist/lib/page-controller.js",
"module": "./dist/lib/page-controller.js",

View File

@@ -1,6 +1,6 @@
{
"name": "@page-agent/ui",
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"main": "./dist/lib/page-agent-ui.js",
"module": "./dist/lib/page-agent-ui.js",

View File

@@ -1,11 +1,11 @@
{
"name": "@page-agent/website",
"private": true,
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"build:website": "vite build",
"preview": "vite preview",
"typecheck": "tsc --noEmit"
},