forked from Shopify/polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
93 lines (86 loc) · 2.37 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
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';
import image from '@rollup/plugin-image';
import postcssShopify from '@shopify/postcss-plugin';
import packageJSON from './package.json';
import {styles} from './config/rollup/plugin-styles';
import {generateScopedName} from './config/rollup/namespaced-classname';
const root = __dirname;
const externalPackages = [
...Object.keys(packageJSON.dependencies),
...Object.keys(packageJSON.peerDependencies),
];
function external(id) {
return externalPackages.some((aPackage) => id.startsWith(aPackage));
}
function plugins({browserslist, stylesConfig}) {
return [
replace({
'{{POLARIS_VERSION}}': packageJSON.version,
delimiters: ['', ''],
}),
nodeResolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
commonjs(),
babel({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
envName: 'production',
exclude: 'node_modules/**',
babelHelpers: 'bundled',
caller: {
browserslistOverride: browserslist,
},
}),
styles({
...stylesConfig,
plugins: [postcssShopify],
}),
image(),
];
}
// eslint-disable-next-line import/no-default-export, import/no-anonymous-default-export
export default [
{
input: `${root}/src/index.ts`,
output: [
{format: 'cjs', file: `${root}/dist/index.js`},
{format: 'esm', dir: `${root}/dist/esm`, preserveModules: true},
],
plugins: plugins({
// Not specifying a browserslist config here to use the default as
// defined in our package.json
stylesConfig: {
mode: 'standalone',
output: 'styles.css',
modules: {
generateScopedName: generateScopedName({includeHash: false}),
},
},
}),
external,
},
{
input: `${root}/src/index.ts`,
output: [
{
format: 'esm',
dir: `${root}/dist/esnext`,
entryFileNames: '[name][extname].esnext',
},
],
preserveModules: true,
plugins: plugins({
browserslist: 'extends @shopify/browserslist-config/latest-evergreen',
stylesConfig: {
mode: 'esnext',
modules: {
generateScopedName: generateScopedName({includeHash: true}),
},
},
}),
external,
},
];