-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
117 lines (111 loc) · 3.08 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import autoprefixer from 'autoprefixer';
import babel from '@rollup/plugin-babel';
import { execSync } from 'child_process';
import cleanup from 'rollup-plugin-cleanup';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import alias from '@rollup/plugin-alias';
import del from 'rollup-plugin-delete';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import path from 'path';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import pkg from './package.json';
import postcss from 'rollup-plugin-postcss';
import replace from '@rollup/plugin-replace';
import strip from '@rollup/plugin-strip';
import svgr from '@svgr/rollup';
import typescript from 'rollup-plugin-typescript2';
import { license } from '../../license.ts';
import { string } from 'rollup-plugin-string';
const mode = {
PRODUCTION: 'production',
DEVELOPMENT: 'development',
};
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const isProduction = process.env.NODE_ENV === mode.PRODUCTION;
const includePattern = 'src/**/*';
const getTagName = () => {
try {
return execSync('git describe --tags --abbrev=0', { encoding: 'utf8' });
} catch (error) {
console.error(error);
return 'master';
}
};
export const valuesToReplace = {
'process.env.NODE_ENV': JSON.stringify(
isProduction ? mode.PRODUCTION : mode.DEVELOPMENT,
),
'process.env.VERSION': JSON.stringify(pkg.version),
'process.env.BUILD_DATE': JSON.stringify(
new Date().toISOString().slice(0, 19),
),
// TODO: add logic to init BUILD_NUMBER
'process.env.BUILD_NUMBER': JSON.stringify(undefined),
'process.env.HELP_LINK': JSON.stringify(getTagName()),
};
const config = {
input: pkg.source,
output: [
{
file: pkg.main,
exports: 'named',
format: 'cjs',
banner: license,
},
{
file: pkg.module,
exports: 'named',
format: 'es',
banner: license,
},
],
plugins: [
alias({
entries: [{ find: 'url', replacement: 'native-url' }],
}),
del({
targets: 'dist/*',
runOnce: true,
}),
postcss({
plugins: [autoprefixer({ grid: 'autoplace' })],
extract: path.resolve('dist/index.css'),
minimize: isProduction,
sourceMap: true,
include: includePattern,
}),
svgr({ include: includePattern }),
peerDepsExternal({ includeDependencies: true }),
nodeResolve({ extensions }),
commonjs(),
replace({
include: includePattern,
preventAssignment: true,
values: valuesToReplace,
}),
json(),
typescript({
tsconfig: './tsconfig.build.json',
}),
babel({
extensions,
babelHelpers: 'runtime',
include: includePattern,
}),
copy({
targets: [{ src: 'src/style/*.svg', dest: 'dist' }],
}),
cleanup({
extensions: extensions.map((ext) => ext.trimStart('.')),
comments: 'none',
include: includePattern,
}),
...(isProduction ? [strip({ include: includePattern })] : []),
string({
include: '**/*.sdf',
}),
],
};
export default config;