Skip to content

Commit

Permalink
build: add umd build script (tusen-ai#3060)
Browse files Browse the repository at this point in the history
Co-authored-by: knight.chen <[email protected]>
  • Loading branch information
keuby and knight.chen authored Jun 8, 2022
1 parent 467ddcc commit 5dcf6e8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"main": "lib/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"unpkg": "dist/naive.prod.js",
"jsdelivr": "dist/naive.prod.js",
"scripts": {
"start": "pnpm run dev",
"dev": "pnpm run clean && pnpm run gen-version && pnpm run gen-volar-dts && cross-env NODE_ENV=development vite",
"build:package": "pnpm run gen-version && pnpm run clean && pnpm run gen-volar-dts && tsc -b --force tsconfig.esm.json && node scripts/pre-build/pre-cjs-build.js && tsc -b --force tsconfig.cjs.json && node scripts/post-build && rimraf {es,lib}/*.tsbuildinfo",
"build:package": "pnpm run gen-version && pnpm run clean && pnpm run gen-volar-dts && tsc -b --force tsconfig.esm.json && node scripts/pre-build/pre-cjs-build.js && tsc -b --force tsconfig.cjs.json && rollup -c && node scripts/post-build && rimraf {es,lib}/*.tsbuildinfo",
"build:site": "./scripts/pre-build-site/pre-build-site.sh && cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && ./scripts/post-build-site/post-build-site.sh",
"clean": "rimraf site lib es node_modules/naive-ui themes/**/es themes/**/lib",
"clean": "rimraf site lib es dist node_modules/naive-ui themes/**/es themes/**/lib",
"release:package": "pnpm run test && pnpm run build:package && pnpm publish --no-git-checks",
"release:changelog": "node scripts/release-changelog",
"lint": "pnpm run lint:code && pnpm run lint:type",
Expand Down Expand Up @@ -38,6 +40,7 @@
"files": [
"es",
"lib",
"dist",
"volar.d.ts",
"web-types.json",
"README.md"
Expand Down Expand Up @@ -75,6 +78,9 @@
"@babel/preset-env": "^7.16.11",
"@babel/traverse": "^7.17.9",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@types/estree": "^0.0.51",
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.18.0",
Expand All @@ -93,6 +99,7 @@
"codesandbox": "^2.2.3",
"cross-env": "^7.0.3",
"cssnano": "^5.1.7",
"deepmerge": "^4.2.2",
"esbuild": "0.14.42",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -117,6 +124,9 @@
"marked": "^4.0.13",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"rollup": "^2.75.6",
"rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-terser": "^7.0.2",
"superagent": "^7.1.3",
"ts-jest": "^28.0.1",
"typescript": "~4.6.3",
Expand Down
69 changes: 69 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const path = require('path')
const merge = require('deepmerge')
const { defineConfig } = require('rollup')
const nodeResolve = require('@rollup/plugin-node-resolve').default
const babel = require('@rollup/plugin-babel').default
const replace = require('@rollup/plugin-replace')
const commonjs = require('@rollup/plugin-commonjs')
const esbuild = require('rollup-plugin-esbuild').default
const { terser } = require('rollup-plugin-terser')

const extensions = ['.mjs', '.js', '.json', '.ts']

const baseConfig = defineConfig({
input: path.resolve('./src/index.ts'),
plugins: [
nodeResolve({ extensions }),
esbuild({
target: 'esnext',
sourceMap: true
}),
babel({
extensions,
babelHelpers: 'bundled'
}),
commonjs()
],
external: ['vue'],
output: {
name: 'naive',
format: 'umd',
exports: 'named',
globals: {
vue: 'Vue'
}
}
})

const devConfig = defineConfig({
plugins: [
replace({
values: {
__DEV__: JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify('development')
},
preventAssignment: true
})
],
output: {
file: path.resolve('dist/naive.js')
}
})

const prodConfig = defineConfig({
plugins: [
replace({
values: {
__DEV__: JSON.stringify(false),
'process.env.NODE_ENV': JSON.stringify('production')
},
preventAssignment: true
}),
terser()
],
output: {
file: path.resolve('dist/naive.prod.js')
}
})

module.exports = [merge(baseConfig, devConfig), merge(baseConfig, prodConfig)]

0 comments on commit 5dcf6e8

Please sign in to comment.