-
Notifications
You must be signed in to change notification settings - Fork 21
/
rollup.config.js
92 lines (87 loc) · 2.36 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
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import filesize from 'rollup-plugin-filesize';
import includePaths from 'rollup-plugin-includepaths';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import autoprefixer from 'autoprefixer';
import stylelint from 'rollup-plugin-stylelint';
import postcssPresetEnv from 'postcss-preset-env';
import {terser} from 'rollup-plugin-terser';
import ts from 'rollup-plugin-ts';
import pkg from './package.json';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const outputs = [
{
file: process.env.REACT_APP_PKG_MAIN || pkg.main,
format: 'umd',
},
{
file: process.env.REACT_APP_PKG_MODULE || pkg.module,
format: 'es',
},
];
const postcssPlugins = [
postcssPresetEnv({
browsers: pkg.browserslist.production,
stage: 3,
}),
autoprefixer(),
];
const config = outputs.map(({file, format}) => ({
input: 'src/lib/index.ts',
output: {
file,
format,
name: 'CommerceSdk',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
exports: 'named',
},
plugins: [
peerDepsExternal(),
includePaths({
include: {},
paths: ['src'],
// crypto is a node built-in, but rollup doesn't seem to know that?
external: ['crypto', ...Object.keys(pkg.dependencies)],
extensions: ['.js', '.json', '.html'],
}),
stylelint({
throwOnError: true,
}),
postcss({
extract: process.env.REACT_APP_PKG_STYLE || pkg.style,
inline: false,
plugins: postcssPlugins,
}),
ts({
transpiler: 'babel',
// Setting noEmit directly in the tsconfig triggers a react testing bug so we override it here
tsconfig: resolvedConfig => ({...resolvedConfig, noEmit: false}),
exclude: 'node_modules/**',
}),
babel({
extensions,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
}),
resolve({
extensions,
browser: true,
}),
commonjs(),
terser(),
filesize(),
],
}));
export default config;