generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
61 lines (54 loc) · 1.54 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
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import copy from 'rollup-plugin-copy';
const PROJECT_NAME = 'dynamic-text-concealer';
const TEST_VAULT_PLUGIN_DIR = `test-vault/.obsidian/plugins/${PROJECT_NAME}`;
const BUILD_DIR = 'build';
const BASE_CONFIG = {
input: 'src/main.ts',
external: ['obsidian', '@codemirror/view', '@codemirror/state', '@codemirror/language'],
};
const getRollupPlugins = (...plugins) => [typescript(), nodeResolve({ browser: true }), commonjs()].concat(plugins);
const DEV_PLUGIN_CONFIG = {
...BASE_CONFIG,
output: {
dir: TEST_VAULT_PLUGIN_DIR,
sourcemap: 'inline',
format: 'cjs',
exports: 'auto',
},
plugins: getRollupPlugins(
copy({
targets: [
{ src: 'manifest.json', dest: `${TEST_VAULT_PLUGIN_DIR}/` },
{ src: 'styles.css', dest: `${TEST_VAULT_PLUGIN_DIR}/` },
],
}),
),
};
const PROD_PLUGIN_CONFIG = {
...BASE_CONFIG,
output: {
dir: BUILD_DIR,
sourcemap: 'inline',
sourcemapExcludeSources: true,
format: 'cjs',
exports: 'auto',
},
plugins: getRollupPlugins(),
};
// TODO: Create environment specific builds (dev, prod, etc.)
// Dataview plugin has a good implementaiton of this
let configs = [];
if (process.env.BUILD === 'prod') {
// Production build
configs.push(PROD_PLUGIN_CONFIG);
} else if (process.env.BUILD === 'dev') {
// Dev build
configs.push(DEV_PLUGIN_CONFIG);
} else {
// Default to the dev build.
configs.push(DEV_PLUGIN_CONFIG);
}
export default configs;