forked from sendbird/sendbird-uikit-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
152 lines (144 loc) · 4.11 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// plugins
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import svgr from "@svgr/rollup";
import scss from "rollup-plugin-scss";
import postcss from "rollup-plugin-postcss";
import replace from "@rollup/plugin-replace";
import autoprefixer from "autoprefixer";
import postcssRtl from "postcss-rtlcss";
import copy from "rollup-plugin-copy";
import nodePolyfills from "rollup-plugin-polyfill-node";
import {visualizer} from "rollup-plugin-visualizer";
import ts2 from "rollup-plugin-typescript2"
// config from package.json
import pkg from "./package.json" assert {type: "json"};
import inputs from "./rollup.module-exports.mjs";
import { readFileSync, writeFileSync } from 'fs';
const APP_VERSION_STRING = "__react_dev_mode__";
export default {
// To bundle split
input: inputs,
output: [
{
dir: "./dist",
chunkFileNames: 'chunks/bundle-[hash].js',
format: "esm",
sourcemap: true,
},
{
dir: "./dist/cjs",
chunkFileNames: 'chunks/bundle-[hash].js',
format: "cjs",
sourcemap: true,
},
],
external: [
"@sendbird/chat",
"@sendbird/chat/groupChannel",
"@sendbird/chat/openChannel",
"@sendbird/chat/message",
"@sendbird/uikit-tools",
"react",
"react-dom",
"css-vars-ponyfill",
"date-fns",
"dompurify",
// todo@v4: remove this
// we do not add ts-pattern as dep to avoid conflict with client base
// 'ts-pattern',
],
plugins: [
postcss({
preprocessor: (content, id) =>
new Promise((resolvecss) => {
const result = scss.renderSync({ file: id });
resolvecss({ code: result.css.toString() });
}),
plugins: [autoprefixer, postcssRtl({ mode: 'override' })],
sourceMap: false,
extract: "dist/index.css",
extensions: [".sass", ".scss", ".css"],
}),
{
name: 'postcss-single-file',
async writeBundle(outputOptions, bundle) {
// Path to your CSS file
const cssFilePath = './dist/dist/index.css';
try {
// Read the content of the CSS file
const cssContent = readFileSync(cssFilePath, 'utf-8');
// Split the content into lines
const lines = cssContent.split('\n');
// Find lines starting with @import
const importLines = [];
const otherLines = [];
lines.forEach(line => {
if (line.trim().startsWith('@import')) {
importLines.push(line);
} else {
otherLines.push(line);
}
});
// Combine import lines and other lines
const modifiedContent = importLines.join('\n') + '\n' + otherLines.join('\n');
// Write the modified content back to the file
writeFileSync(cssFilePath, modifiedContent);
console.log('Moved @import lines to the top of the CSS file successfully.');
} catch (error) {
console.error('Error occurred while moving @import lines to the top of the CSS file:', error);
}
},
},
replace({
preventAssignment: false,
exclude: "node_modules/**",
[APP_VERSION_STRING]: pkg.version,
}),
ts2({
tsconfig: 'tsconfig.json',
tsconfigOverride: {
compilerOptions:{
declaration: false,
}
}
}),
svgr(),
resolve({
preferBuiltins: true,
}),
commonjs(),
nodePolyfills({
include: ["buffer", "stream"],
}),
copy({
verbose: true,
targets: [
{
src: "./README.md",
dest: "dist",
},
{
src: "./LICENSE",
dest: "dist",
},
{
src: "./CHANGELOG.md",
dest: "dist",
},
{
src: "./yarn.lock", // Allows us to go yarn link path/to/package while doing local dev
dest: "dist",
},
],
}),
visualizer({
filename: "bundle-analysis.json",
gzipSize: true,
template: "raw-data",
brotliSize: false,
}),
// Uncomment the below line, if you want to see box-graph of bundle size
// visualizer(),
],
};