forked from Dogfalo/materialize
-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
rollup.config.ts
185 lines (173 loc) · 4.67 KB
/
rollup.config.ts
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import type { RollupOptions } from 'rollup';
import typescriptPlugin from '@rollup/plugin-typescript';
import terserPlugin from '@rollup/plugin-terser';
import dtsPlugin from 'rollup-plugin-dts';
import scss from 'rollup-plugin-scss';
import copy from 'rollup-plugin-copy';
import { readFileSync } from 'fs';
const packageJson = JSON.parse(readFileSync('./package.json').toString());
const outputPath = 'dist/js/materialize';
const version = packageJson.version;
const bannerText = `/*!
* Materialize v${version} (https://materializeweb.com)
* Copyright 2014-${new Date().getFullYear()} Materialize
* MIT License (https://raw.githubusercontent.com/materializecss/materialize/master/LICENSE)
*/`;
const config: RollupOptions[] = [
//--- Replace version in index.ts
{
input: './ci/empty.js',
plugins: [
copy({
targets: [
{
src: `src/index.ts`,
dest: `src`,
transform: (contents) =>
contents
.toString()
.replace(
new RegExp(/export const version = '.*/),
`export const version = '${version}';`
)
}
]
})
],
onwarn: (warning, defaultHandler) => {
if (warning.code !== 'EMPTY_BUNDLE') defaultHandler(warning);
}
},
//--- JS
{
input: 'src/index.ts',
plugins: [typescriptPlugin()],
output: [
{
file: `${outputPath}.cjs.js`,
banner: bannerText,
format: 'cjs'
}
]
},
{
input: 'src/index.ts',
plugins: [typescriptPlugin()],
output: [
{
file: `${outputPath}.mjs`,
banner: bannerText,
format: 'esm'
}
]
},
{
input: 'src/index.ts',
plugins: [typescriptPlugin()],
output: [
{
name: 'M',
file: `${outputPath}.js`,
banner: bannerText,
format: 'iife'
},
{
name: 'M',
file: `${outputPath}.min.js`,
format: 'iife',
banner: bannerText,
plugins: [terserPlugin()]
}
]
},
//--- Types
{
input: 'src/index.ts',
plugins: [typescriptPlugin(), dtsPlugin()],
output: [
{
file: `${outputPath}.d.ts`,
format: 'esm'
}
]
},
//--- CSS
{
input: 'sass/materialize.scss',
output: [{ file: 'dist/css/materialize.min.css' }], // overwritten
plugins: [
scss({
fileName: 'materialize.min.css',
outputStyle: 'compressed',
sourceMap: true
})
],
onwarn: (warning, defaultHandler) => {
if (!(warning.code === 'FILE_NAME_CONFLICT' || warning.code === 'EMPTY_BUNDLE'))
defaultHandler(warning);
}
},
{
input: 'sass/materialize.scss',
output: [{ file: 'dist/css/materialize.css' }], // overwritten
plugins: [
scss({
fileName: 'materialize.css'
})
],
onwarn: (warning, defaultHandler) => {
if (!(warning.code === 'FILE_NAME_CONFLICT' || warning.code === 'EMPTY_BUNDLE'))
defaultHandler(warning);
}
},
//--- CSS Banners
{
input: './ci/empty.js',
plugins: [
copy({
targets: [
{
src: `dist/css/materialize.css`,
dest: `dist/css`,
transform: (contents) => [bannerText, contents].join('\n')
},
{
src: `dist/css/*.min.css`,
dest: `dist/css`,
transform: (contents) => [bannerText, contents.toString().substring(1)].join('\n') // bug => workaround
}
]
})
],
onwarn: (warning, defaultHandler) => {
if (warning.code !== 'EMPTY_BUNDLE') defaultHandler(warning);
}
}
// TODO: Compress as zip files
// compress: {
// main: {
// options: {
// archive: 'bin/materialize-v'+version+'.zip',
// level: 6
// },
// files: [
// { expand: true, cwd: 'dist/', src: ['**/*'], dest: 'materialize/' },
// { expand: true, cwd: './', src: ['LICENSE', 'README.md'], dest: 'materialize/' }
// ]
// },
// src: {
// options: {
// archive: 'bin/materialize-src-v'+version+'.zip',
// level: 6
// },
// files: [
// { expand: true, cwd: 'sass/', src: ['materialize.scss'], dest: 'materialize-src/sass/' },
// { expand: true, cwd: 'sass/', src: ['components/**/*'], dest: 'materialize-src/sass/' },
// { expand: true, cwd: 'src/', src: ['**/*'], dest: 'materialize-src/ts/' },
// { expand: true, cwd: 'dist/js/', src: ['**/*'], dest: 'materialize-src/js/bin/' },
// { expand: true, cwd: './', src: ['LICENSE', 'README.md'], dest: 'materialize-src/' }
// ]
// }
// },
];
export default config;