-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathrollup.config.js
99 lines (93 loc) · 2.49 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
import replacePlugin from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import filesize from 'rollup-plugin-filesize';
import fs from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
const deps = Object.keys(pkg.dependencies);
const external = (id) => deps.some((dep) => id.startsWith(dep));
const replace = replacePlugin({
preventAssignment: true,
__VERSION__: pkg.version,
});
/** @type {import('rollup').MergedRollupOptions[]} */
export default [
{
input: {
'utils/index': './src/utils/index.js',
account: './src/account.js',
api: './src/api.js',
attributes: './src/attributes.js',
cache: './src/cache.js',
card: './src/card.js',
cart: './src/cart.js',
categories: './src/categories.js',
content: './src/content.js',
cookie: './src/cookie.js',
currency: './src/currency.js',
locale: './src/locale.js',
payment: './src/payment/index.js',
products: './src/products.js',
settings: './src/settings.js',
subscriptions: './src/subscriptions.js',
index: './src/index.js',
},
external,
output: [
{
dir: './dist',
chunkFileNames: '[name].[hash].mjs',
entryFileNames: '[name].mjs',
generatedCode: {
preset: 'es2015',
constBindings: true,
objectShorthand: true,
},
format: 'es',
},
],
plugins: [replace, resolve(), commonjs(), filesize()],
},
{
input: './src/index.js',
output: [
{
name: 'swell',
sourcemap: true,
exports: 'default',
file: pkg.main,
generatedCode: {
preset: 'es2015',
constBindings: true,
objectShorthand: true,
},
format: 'cjs',
},
],
external,
plugins: [replace, resolve(), commonjs(), filesize()],
},
{
input: './src/index.js',
output: [
{
name: 'swell',
sourcemap: true,
exports: 'default',
file: pkg.browser,
format: 'umd',
},
],
plugins: [
replace,
nodePolyfills({ exclude: ['node_modules/object-inspect/**'] }),
resolve(),
commonjs(),
filesize(),
],
},
];