generated from MetamorfosiLab/lib-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup-full.config.ts
130 lines (122 loc) · 2.86 KB
/
rollup-full.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type { LoggingFunction, RollupLog, RollupOptions } from 'rollup'
import { defineConfig } from 'rollup'
import terser from '@rollup/plugin-terser'
import postcssCombineDuplicatedSelectors from 'postcss-combine-duplicated-selectors'
import cssnanoPlugin from 'cssnano'
import postcss from 'rollup-plugin-postcss'
import postcssImport from 'postcss-import'
import ts from 'rollup-plugin-ts'
import pkg from './package.json' assert { type: 'json' }
const srcDir = './src'
const distDir = './dist'
const cssComponentsDir = `${distDir}/css/modules`
const input = `${srcDir}/index.ts`
// eslint-disable-next-line node/prefer-global/process
const productionMode = !process.env.ROLLUP_WATCH
export const banner = `/*!
* ${pkg.name} ${pkg.version}
* ${pkg.repository.url}
* Author ${pkg.author}
* Released under the ${pkg.license} License
*/
`
const cssComponents = [
[
'themes/_custom.pcss',
'custom-theme.css',
],
]
const cssComponentsRollup = cssComponents.map((component) => {
const src = `${srcDir}/styles/${component[0]}`
const dst = `${cssComponentsDir}/${component[1]}`
return {
input: src,
output: {
file: dst,
},
plugins: postcss({
extract: true,
plugins: [
postcssImport(),
postcssCombineDuplicatedSelectors(),
productionMode && cssnanoPlugin({
preset: ['default', {
discardComments: {
removeAll: true,
},
}],
}),
],
}),
onwarn(warning: RollupLog, warn: LoggingFunction) {
if (warning.code === 'FILE_NAME_CONFLICT')
return
warn(warning)
},
}
})
export const terserPlugin = terser({
toplevel: true,
format: {
quote_style: 1,
comments: /^!/,
},
mangle: {
properties: {
regex: /^_/,
reserved: ['__esModule', '_ccRun'],
keep_quoted: true,
},
},
compress: {
passes: 3,
pure_funcs: ['_log', 'console.log'],
},
})
export default defineConfig(
[{
input,
output: [
{
file: pkg.main,
format: 'umd',
name: pkg.shortName,
banner,
},
{
file: pkg.module,
format: 'esm',
exports: 'named',
banner,
},
],
plugins: [
ts(),
productionMode && terserPlugin,
],
}, {
input: `${srcDir}/styles/index.pcss`,
output: {
file: `${distDir}/css/${pkg.shortName}.css`,
},
plugins: postcss({
extract: true,
plugins: [
postcssImport(),
postcssCombineDuplicatedSelectors(),
productionMode && cssnanoPlugin({
preset: ['default', {
discardComments: {
removeAll: true,
},
}],
}),
],
}),
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT')
return
warn(warning)
},
}, ...cssComponentsRollup] as RollupOptions[],
)