-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrollup.config.mjs
151 lines (146 loc) · 3.53 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
import json from '@rollup/plugin-json';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import strip from '@rollup/plugin-strip';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import {createFilter} from '@rollup/pluginutils';
import postcss from 'rollup-plugin-postcss'
export default [
// {
// input: './src/index.ts',
// output: {
// file: './dist/index.js',
// format: 'es',
// },
// plugins: [
// stringWgsl(),
// nodeResolve(),
// json(),
// postcss({
// inject: true, // 기본값입니다. 이 결과를 JavaScript 번들에 주입합니다.
// extensions: ['.css'],
// minimize: true
// }),
// strip({
// include: ['**/*.ts'], // 모든 TypeScript 파일을 대상으로 함
// exclude: ["./init.ts"], // 특정 파일은 제거 대상에서 제외
// functions: ['console.log'], // 제거할 함수 지정
// debugger: true, // debugger 문 제거
// }),
// typescript({
// tsconfig: 'tsconfig.json'
// }
// ),
// terser({
// format: {
// comments: false,
// },
// mangle: false,
// compress: {
// dead_code: true,
// if_return: true
// },
// }),
// removeSpacesAndTabs()
// ]
// },
{
input: './src/index.ts',
output: {
file: './dist/index.js',
format: "es",
},
plugins: [
stringWgsl(),
nodeResolve(),
json(),
postcss({
inject: true, // 기본값입니다. 이 결과를 JavaScript 번들에 주입합니다.
extensions: ['.css'],
minimize: true
}),
strip(
{
include: ['**/*.ts'],
exclude: ["./init.ts"],
functions: ['console.log'], // 제거할 함수 지정
debugger: true,
}
),
typescript({
tsconfig: 'tsconfig.json'
}
),
terser({
format: {
comments: false,
},
mangle: {
properties: false,
keep_classnames: true,
keep_fnames: true,
},
compress: {
dead_code: true,
if_return: true
},
}),
removeSpacesAndTabs()
]
},
]
function removeSpacesAndTabs() {
return {
generateBundle(_, bundle) {
for (const filename in bundle) {
const file = bundle[filename];
if (file.type === 'chunk') {
file.code = file.code
.replace(/(\\t){2,}/g, '\t')
.replace(/(\s?)=(\s?)/g, '=')
.replace(/(\s?):(\s?)/g, ':')
.replace(/(\s?);(\s?)/g, ';')
.replace(/(\s?),(\s?)/g, ',')
.replace(/(\s?)\/(\s?)/g, '/')
.replace(/\s{1,}/g, ' ')
.replace(/\\n /g, '')
;
}
}
}
};
}
function stringWgsl() {
const filter = createFilter('**/*.wgsl');
return {
name: 'remove-tab-characters-from-wgsl',
transform(code, id) {
if (filter(id)) {
let newCode = code
.replace(/\/\/.*/g, '')
// .replace(/(\s|\\t){1,}/g, ' ')
// .replace(/\\t/g, ' ')
// .replace(/(\s?)=(\s?)/g, '=')
// .replace(/(\s?):(\s?)/g, ':')
// .replace(/(\s?);(\s?)/g, ';')
// .replace(/(\s?),(\s?)/g, ',')
// .replace(/(\s?)\/(\s?)/g, '/')
// .replace(/(\s?)\*(\s?)/g, '*')
// .replace(/\s-|-\s|\s-\s/g, '-')
// .replace(/(\s?)\+(\s?)/g, '+')
// .replace(/(\s?)\{(\s?)/g, '{')
// .replace(/(\s?)}(\s?)/g, '}')
// .replace(/(\s?)>(\s?)/g, '>')
// .replace(/(\s?)<(\s?)/g, '<')
// .replace(/(\s?)\((\s?)/g, '(')
// .replace(/(\s?)\)(\s?)/g, ')')
// newCode = newCode.replace(/return/g, 'return ');
newCode = JSON.stringify(newCode)
return {
code: `export default ${newCode};`,
map: {mappings: ""}
};
}
}
};
}