-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.js
82 lines (77 loc) · 2.45 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
import typescript from 'typescript';
import pluginTypeScript from '@rollup/plugin-typescript';
import del from 'rollup-plugin-delete';
import externals from 'rollup-plugin-node-externals';
import visualize from 'rollup-plugin-visualizer';
import tsConfig from './tsconfig.json';
import pkg from './package.json';
import { promises as fs } from 'fs';
import path from 'path';
const externalDependencies = ['react', 'react-dom', 'react-spring', '@reach/dialog'];
const TypeScriptConfigs = {
legacy: {
...tsConfig.compilerOptions,
include: tsConfig.include,
exclude: tsConfig.exclude,
target: 'ES2015',
module: 'ES2015',
typescript,
declaration: true
},
modern: {
...tsConfig.compilerOptions,
include: tsConfig.include,
exclude: tsConfig.exclude,
target: 'ES2020',
module: 'ES2020',
typescript,
declaration: true,
declarationDir: './dist/modern/'
}
};
const delConfig = { targets: ['./dist/*', './styles.css'] };
function copyStyles() {
return {
async buildEnd() {
try {
await fs.copyFile(path.join(process.cwd(), 'src', 'styles.css'), path.join(process.cwd(), 'styles.css'));
console.log('./src/styles.css → ./styles.css');
} catch (error) {
console.log('Unable to copy ./src/style.css to ./styles.css');
console.error(error);
}
}
};
}
export default [
{
input: pkg.source,
plugins: [
externals({ deps: true }), // automatic externalization of dependencies
visualize({ filename: 'stats/commonjs.html' }), // creates a visualization of the bundle
// so Rollup can convert TypeScript to JavaScript
pluginTypeScript({ ...TypeScriptConfigs.legacy, declarationDir: './dist/commonjs/' }),
copyStyles(), // so we can have CSS!
del(delConfig) // so the "dist/" folder is empty before we write
],
output: { dir: './dist/commonjs/', format: 'cjs', sourcemap: true }
},
{
input: pkg.source,
plugins: [
externals({ deps: true }),
visualize({ filename: 'stats/module.html' }),
pluginTypeScript({ ...TypeScriptConfigs.legacy, declarationDir: './dist/module/' })
],
output: { dir: './dist/module/', format: 'es', sourcemap: true }
},
{
input: pkg.source,
plugins: [
visualize({ filename: 'stats/modern.html' }),
externals({ deps: true }),
pluginTypeScript(TypeScriptConfigs.modern)
],
output: { dir: './dist/modern/', format: 'es', sourcemap: true }
}
];