-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.ts
85 lines (83 loc) · 2.08 KB
/
rollup.config.ts
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
75
76
77
78
79
80
81
82
83
84
85
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import fs from 'fs';
import { glob } from 'glob';
import path from 'path';
import { defineConfig, Plugin, RollupOptions } from 'rollup';
import html from 'rollup-plugin-create-html';
import postcss from 'rollup-plugin-postcss';
import typescript from 'rollup-plugin-typescript2';
// 目标目录
const distDir = 'dist';
// 源文件目录
const srcDir = 'src';
export default defineConfig([
{
input: './src/popup/index.ts',
output: {
format: 'es',
dir: `${distDir}/popup`,
},
watch: {
buildDelay: 500,
},
plugins: [
postcss({ extract: true, minimize: true }),
html({
template: './src/popup/index.html',
title: 'tech-study-plugin',
prefix: './',
meta: {
name: 'description',
content: 'A browser plugin helps you study joyfully on xuexi.com.',
},
link: {
rel: 'icon',
href: './src/assets/icon.jpg',
},
inject: {
'index.js': {
defer: true,
location: 'head',
},
},
}),
resolve(),
commonjs(),
typescript(),
terser(),
<Plugin>{
name: 'temp',
writeBundle(options) {
// 生成文件夹
const { dir } = options;
if (dir) {
// 目标文件夹
const distDir = path.dirname(dir);
fs.cpSync('./src/assets', path.join(distDir, './assets'), {
recursive: true,
});
}
},
},
],
},
...glob
.sync('./src/@(inject|background)/**/*.ts')
.map<RollupOptions>((file) => {
// 目录
const dir = path.join(distDir, path.dirname(file).replace(srcDir, ''));
return {
input: file,
output: {
format: 'es',
dir,
},
watch: {
buildDelay: 500,
},
plugins: [resolve(), commonjs(), typescript(), terser()],
};
}),
]);