-
Notifications
You must be signed in to change notification settings - Fork 55
/
rollup.config.mjs
87 lines (85 loc) · 2.5 KB
/
rollup.config.mjs
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
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import preserveDirectives from 'rollup-plugin-preserve-directives';
import progress from 'rollup-plugin-progress';
import { visualizer } from 'rollup-plugin-visualizer';
/**
* @type {import('rollup').OutputOptions
*/
const SHARED_OUTPUT_OPTIONS = {
dir: 'lib',
preserveModules: true,
preserveModulesRoot: 'src',
sourcemap: true,
};
export default defineConfig({
input: ['src/octuple.ts', 'src/locale.ts'],
output: [
{
...SHARED_OUTPUT_OPTIONS,
chunkFileNames: '[name]-[hash].js',
entryFileNames: '[name].js',
format: 'cjs',
},
{
...SHARED_OUTPUT_OPTIONS,
chunkFileNames: '[name]-[hash].mjs',
entryFileNames: '[name].mjs',
format: 'es',
},
],
plugins: [
progress(),
postcss({
modules: { localsConvention: 'camelCase' },
minimize: true,
extract: 'octuple.css',
inject: false, // don't inject <style> tags for components
// link the variable definitions to the source files (since main.scss is not imported in the library code)
use: { sass: { data: '@import "./src/styles/main.scss";' } },
}),
peerDepsExternal(), // ensures peer deps like "react" and "react-dom" are not bundled
resolve(),
commonjs(),
json(),
preserveDirectives(), // preserve "use client" directives
typescript({
tsconfig: './tsconfig.json',
exclude: [
'.storybook',
'storybook-static',
'config',
'coverage',
'lib',
'node_modules/**',
'*.cjs',
'*.mjs',
'**/__snapshots__/**',
'**/tests/**',
'**/Tests/**',
'**/*.test.js+(|x)',
'**/*.test.ts+(|x)',
'**/*.stories.ts+(|x)',
'**/*.stories.js+(|x)',
],
}),
terser({ keep_fnames: true }),
visualizer(),
],
/**
* Ignore warnings about "use client" directive, these are preserved by rollup-plugin-preserve-directives
* @see https://github.com/Ephem/rollup-plugin-preserve-directives?tab=readme-ov-file#disabling-warnings
*/
onwarn(warning, warn) {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return;
}
warn(warning);
},
});