This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
generated from tweakpane/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
101 lines (92 loc) · 2.37 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
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
import Alias from '@rollup/plugin-alias';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import Replace from '@rollup/plugin-replace';
import Typescript from '@rollup/plugin-typescript';
import Autoprefixer from 'autoprefixer';
import NodeSass from 'node-sass';
import Postcss from 'postcss';
import Cleanup from 'rollup-plugin-cleanup';
import {terser as Terser} from 'rollup-plugin-terser';
import Package from './package.json';
async function compileCss() {
const css = NodeSass.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 = [
Alias({
entries: [
{
find: '@tweakpane/core',
replacement: './node_modules/@tweakpane/core/dist/es6/index.js',
},
],
}),
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) {
// `@tweakpane/plugin-foobar` -> `tweakpane-plugin-foobar`
// `tweakpane-plugin-foobar` -> `tweakpane-plugin-foobar`
return packageName
.split(/[@/-]/)
.reduce((comps, comp) => (comp !== '' ? [...comps, comp] : comps), [])
.join('-');
}
function getUmdName(packageName) {
// `@tweakpane/plugin-foobar` -> `TweakpaneFoobarPlugin`
// `tweakpane-plugin-foobar` -> `TweakpaneFoobarPlugin`
return (
packageName
.split(/[@/-]/)
.map((comp) =>
comp !== 'plugin' ? comp.charAt(0).toUpperCase() + comp.slice(1) : '',
)
.join('') + 'Plugin'
);
}
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',
output: {
file: `dist/${distName}${postfix}.js`,
format: 'umd',
name: getUmdName(Package.name),
},
plugins: getPlugins(css, production),
// Suppress `Circular dependency` warning
onwarn(warning, rollupWarn) {
if (warning.code === 'CIRCULAR_DEPENDENCY') {
return;
}
rollupWarn(warning);
},
};
};