-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
rollup.config.mjs
82 lines (77 loc) · 2.34 KB
/
rollup.config.mjs
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
import { createRequire } from 'node:module'
import path from 'node:path'
import url from 'node:url'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'
import postcssUrl from 'postcss-url'
import postcss from 'rollup-plugin-postcss'
import { string } from 'rollup-plugin-string'
import { postcssOptimizeDefaultTheme } from './scripts/postcss-optimize-default-theme.mjs' // eslint-disable-line import-x/namespace -- false positive?
const require = createRequire(import.meta.url)
const pkg = require('./package.json')
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
const plugins = ({ browser = false } = {}) => [
json({ preferConst: true }),
alias({
entries: [
{
find: /^.+browser-script$/,
replacement: path.resolve(__dirname, 'lib/browser.js'),
},
],
}),
string({ include: ['lib/*.js'] }),
nodeResolve({ browser }),
commonjs(),
typescript(),
postcss({
inject: false,
plugins: [
postcssOptimizeDefaultTheme(),
postcssUrl({
filter: '**/assets/**/*.svg',
encodeType: 'base64',
url: 'inline',
}),
autoprefixer(),
cssnano({
preset: [
'default',
{
// Whitespace normalizer will apply on runtime to make debug easily (minifyCSS option)
normalizeWhitespace: false,
},
],
}),
],
}),
!process.env.ROLLUP_WATCH && terser(),
]
const external = (deps) => (id) =>
deps.some((dep) => dep === id || id.startsWith(`${dep}/`))
export default [
// Browser helpers
{
input: 'scripts/browser.js',
output: { file: 'lib/browser.js', format: 'iife' },
plugins: plugins({ browser: true }),
},
{
input: 'src/browser.ts',
output: { exports: 'named', file: 'lib/browser.cjs.js', format: 'cjs' },
plugins: plugins({ browser: true }),
},
// Main bundle
{
external: external(Object.keys(pkg.dependencies)),
input: `src/${path.basename(pkg.main, '.js')}.ts`,
output: { exports: 'named', file: pkg.main, format: 'cjs' },
plugins: plugins(),
},
]