This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmicrobundle.config.js
71 lines (61 loc) · 2.06 KB
/
microbundle.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
const image = require('@rollup/plugin-image')
const tailwind = require('tailwindcss')
const assets = require('postcss-assets')
module.exports = {
plugins: {
postcss: function (config) {
// Inject TailwindCSS into the PostCSS config
return {
...config,
plugins: [
tailwind(),
...config.plugins,
assets({
basePath: './src',
}),
],
}
},
typescript: function (config) {
// Since imported *.svg will be transformed to ES modules by the image plugin, tell
// TypeScript to process them
return { ...config, include: ['*.ts+(|x)', '**/*.ts+(|x)', '*.s?css', '*.svg', '**/*.svg'] }
},
},
config: function (config, context) {
const {
format,
options: { pkg },
} = context
// Add image plugin right after json plugin
const jsonIdx = config.inputOptions.plugins.findIndex((p) => p.name === 'json')
config.inputOptions.plugins = [
...config.inputOptions.plugins.slice(0, jsonIdx + 1),
image(),
...config.inputOptions.plugins.slice(jsonIdx + 1),
]
config.inputOptions.plugins.splice(jsonIdx + 1, 0, image())
// When building browser "standalone" bundles, make sure we inline dependencies
if (format === 'umd') {
const _external = config.inputOptions.external
config.inputOptions.external = (id, ...args) => {
if (
id in (pkg.dependencies || {}) ||
id in (pkg.peerDependencies || {}) ||
// preact imports internal modules that we need inlined into the lib as well
id.match(/^preact\//) ||
id.match(/\.svg$/)
) {
return false
}
return _external(id, ...args)
}
// Make sure @alma/client is exported on the `Alma` global object, and deactivate cache to
// ensure the lib is indeed inlined into the bundle
// (see https://github.com/rollup/rollup/issues/3874)
config.outputOptions.globals['@alma/client'] = 'Alma'
config.inputOptions.cache = false
}
return config
},
}