forked from egoist/ts-lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
74 lines (69 loc) · 2.02 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import fs from 'node:fs'
import typescript from '@rollup/plugin-typescript'
// import typescript from 'rollup-plugin-typescript2'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { format } from 'date-fns'
import camelCase from 'camelcase'
const pkgStr = fs.readFileSync('./package.json')
const pkg = JSON.parse(pkgStr)
const parsedName = pkg.name
.replace('@', '')
.split('/')
.map(r => camelCase(r, { pascalCase: true }))
.join('-')
const globalName = camelCase(parsedName, { pascalCase: true })
const fileName = [
parsedName.toLowerCase(),
// pkg.version,
//
].join('-')
const outputFile = `${fileName}.js`
const outputMinFile = `${fileName}.min.js`
const buildTime = format(new Date(), 'yyyy-MM-dd_HH:mm:ss_SSS')
const bannerFactory = (options = {}) => {
const { name, version, author, build } = Object.assign(
{
version: pkg.version,
author: pkg.author,
build: buildTime,
},
options,
)
return `/*!!\n * Copyright (c) 2022-PRESENT 0ahz (https://github.com/0ahz)\n * Name: ${name}\n * Version: ${version}\n * Author: ${author}\n * Build: ${build}\n*/`
}
console.log({ globalName, outputFile, outputMinFile, buildTime })
export default [
{
input: 'src/index.ts',
output: [
{
name: globalName,
file: `dist/${outputFile}`,
strict: true,
format: 'umd',
dynamicImportInCjs: true,
sourcemap: false,
banner: bannerFactory({ name: outputFile }),
},
{
name: globalName,
file: `dist/${outputMinFile}`,
strict: true,
format: 'umd',
dynamicImportInCjs: true,
sourcemap: false,
banner: bannerFactory({ name: outputMinFile }),
plugins: [terser({ format: { comments: /^!!/ } })],
},
],
plugins: [
json(),
commonjs(),
nodeResolve(),
typescript({ tsconfig: './tsconfig.json' }),
],
},
]