forked from panGenerator/tweakpane-textarea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
76 lines (67 loc) · 1.71 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
/* eslint-env node */
import {nodeResolve} from '@rollup/plugin-node-resolve';
import Replace from '@rollup/plugin-replace';
import Typescript from '@rollup/plugin-typescript';
import Autoprefixer from 'autoprefixer';
import Postcss from 'postcss';
import Cleanup from 'rollup-plugin-cleanup';
import terser from '@rollup/plugin-terser';
import * as Sass from 'sass';
import Package from './package.json' with {type: 'json'};
async function compileCss() {
const css = Sass.renderSync({
file: 'src/sass/plugin.scss',
outputStyle: 'compressed',
}).css.toString();
const result = await Postcss([Autoprefixer]).process(css, {
from: undefined,
});
return result.css.replace(/'/g, "\\'").trim();
}
function getPlugins(css, shouldMinify) {
const plugins = [
Typescript({
tsconfig: 'src/tsconfig.json',
}),
nodeResolve(),
Replace({
__css__: css,
preventAssignment: false,
}),
];
if (shouldMinify) {
plugins.push(terser());
}
return [
...plugins,
// https://github.com/microsoft/tslib/issues/47
Cleanup({
comments: 'none',
}),
];
}
function getDistName(packageName) {
return packageName.replace(/^@[^\/]+\//, '');
}
export default async () => {
const production = process.env.BUILD === 'production';
const postfix = production ? '.min' : '';
const distName = getDistName(Package.name);
const css = await compileCss();
return {
input: 'src/index.ts',
external: ['tweakpane', '@tweakpane/core'],
output: {
file: `dist/${distName}${postfix}.js`,
format: 'esm',
},
plugins: getPlugins(css, production),
// Suppress `Circular dependency` warning
onwarn(warning, rollupWarn) {
if (warning.code === 'CIRCULAR_DEPENDENCY') {
return;
}
rollupWarn(warning);
},
};
};