-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.js
85 lines (75 loc) · 2 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
75
76
77
78
79
80
81
82
83
84
85
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import strip from '@rollup/plugin-strip';
import postcss from 'rollup-plugin-postcss';
import { terser } from "rollup-plugin-terser";
// const packagesDir = path.resolve(__dirname, 'packages')
const targetDir = path.resolve(__dirname)
const srcDir = path.resolve(targetDir, 'src')
const resolve = p => path.resolve(srcDir, p)
let conf = createConfig('', {
file: path.resolve(targetDir, `dist/index.js`),
format: `es`
})
// export default conf
export default [createConfig('', {
file: path.resolve(targetDir, `dist/index.js`),
format: `es`
}), createConfig("iife", {
file: path.resolve(targetDir, `dist/index-browser.js`),
format: `iife`,
name: '__GLOBAL__'
})]
function createConfig(format, output, plugins = []) {
const entryFile = `index.ts`
output.sourcemap = true
const tsPlugin = ts({
check: true,
tsconfig: path.resolve(targetDir, 'tsconfig.json'),
cacheRoot: path.resolve(targetDir, 'node_modules/.rts2_cache'),
useTsconfigDeclarationDir: true,
tsconfigDefaults: {
declaration: true,
declarationDir: 'dist',
}
})
const nodePlugins = format !== 'cjs'
? [
require('@rollup/plugin-node-resolve').nodeResolve({
preferBuiltins: true
}),
require('@rollup/plugin-commonjs')({
sourceMap: false
}),
require('rollup-plugin-node-builtins')(),
require('rollup-plugin-node-globals')()
]
: []
const cssPlugins = [postcss({
extract: true,
modules: false,
use: ['sass'],
})]
const terserPlugin = process.env.NODE_ENV === 'production'?[terser(), strip({
include: ['**/*.ts'],
functions: ['console.*'],
})]:[]
return {
input: resolve(entryFile),
plugins: [
tsPlugin,
...nodePlugins,
...cssPlugins,
...terserPlugin
],
output,
onwarn: (warn) => {
if (warn.code === 'THIS_IS_UNDEFINED') {
return
}
},
treeshake: {
moduleSideEffects: false
}
}
}