forked from source-academy/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
100 lines (90 loc) · 2.9 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import chalk from 'chalk';
import typescript from '@rollup/plugin-typescript';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonJS from 'rollup-plugin-commonjs';
import injectProcessEnv from 'rollup-plugin-inject-process-env';
import filesize from 'rollup-plugin-filesize';
import copy from 'rollup-plugin-copy';
import modules from './modules.json';
const suppressedWarnings = ['MISSING_NAME_OPTION_FOR_IIFE_EXPORT'];
const defaultConfigurations = {
onwarn(warning, warn) {
if (suppressedWarnings.includes(warning.code)) return;
warn(warning);
},
plugins: [
typescript(),
babel({
babelHelpers: 'bundled',
extensions: ['.ts', '.tsx'],
include: ['src/**/*'],
}),
resolve({
// Source Academy's modules run in a browser environment. This setting when
// set to false can cause problems with some imported packages that depend
// on this setting to compile properly.
// @see https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
browser: true,
// If true, the plugin will prefer built-in modules (e.g. fs, path).
// The broswer's environment (jsdom), unlike node environment, does not
// have built-in modules such as fs or path.
// @see https://github.com/rollup/plugins/tree/master/packages/node-resolve#preferbuiltins
preferBuiltins: false,
}),
commonJS({
include: 'node_modules/**',
}),
injectProcessEnv({
NODE_ENV: process.env.NODE_ENV,
}),
filesize({
showMinifiedSize: false,
showGzippedSize: false,
}),
copy({
targets: [{ src: './modules.json', dest: './build' }],
}),
],
};
const moduleBundles = Object.keys(modules);
const buildBundles = (name) => ({
...defaultConfigurations,
input: `./src/bundles/${name}/index.ts`,
output: {
file: `./build/bundles/${name}.js`,
format: 'iife',
},
});
let moduleTabs = [];
moduleBundles
.map((modulePackage) => modules[modulePackage].tabs)
.forEach((__tabs) => Array.prototype.push.apply(moduleTabs, __tabs));
moduleTabs = [...new Set(moduleTabs)];
const buildTabs = (name) => ({
...defaultConfigurations,
input: `./src/tabs/${name}/index.tsx`,
output: {
file: `./build/tabs/${name}.js`,
format: 'iife',
globals: {
react: 'React',
'react-dom': 'ReactDom',
},
},
external: ['react', 'react-dom'],
});
// eslint-disable-next-line no-console
console.log(chalk.blueBright('Building modules with tabs:'));
moduleBundles.forEach((modulePackage) => {
// eslint-disable-next-line no-console
console.log(
chalk.green(`Module ${modulePackage}`),
'with',
chalk.yellow(`tabs ${modules[modulePackage].tabs}`)
);
});
export default [
...moduleBundles.map(buildBundles),
...moduleTabs.map(buildTabs),
];