-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
62 lines (56 loc) · 1.98 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
// Adapted from https://developers.livechatinc.com/blog/how-to-create-javascript-libraries-in-2018-part-1/
import babel from '@rollup/plugin-babel';
import html from 'rollup-plugin-html'; // note: @rollup/plugin-html is *not* an upgrade to this
import postcss from 'rollup-plugin-postcss'
import postcssBanner from 'postcss-banner';
import postcssPresetEnv from 'postcss-preset-env';
import pkg from './package.json';
const externals = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const production = process.env.BUILD === "production";
const banner = `${pkg.name} ${pkg.version} - ${pkg.repository}`;
const bannerJS = `/*! ${banner} */`;
export default {
input: 'src/index.js',
external: externals,
plugins: [
postcss({
// extract: true, // uncomment for external css files
minimize: production, // uses cssnano
plugins: [
postcssBanner({ banner, important: true, inline: true }),
postcssPresetEnv(),
],
sourceMap: !production, // inlined, so don't include in production
}),
html({
include: '**/*.html',
htmlMinifierOptions: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
quoteCharacter: "'", // avoids excessive escaping in generated JS
removeComments: production,
},
}),
babel({
babelHelpers: 'bundled',
comments: !production,
presets: [production && "babel-preset-minify"].filter(Boolean),
}),
],
output: [
{ file: outputFilename(pkg.main), format: 'umd', name: 'RateTheDocs',
banner: bannerJS, sourcemap: true },
{ file: outputFilename(pkg.module), format: 'esm',
banner: bannerJS, sourcemap: true },
],
};
function outputFilename(filename) {
// Ensure ".min" before extension in production, remove ".min" otherwise
const nonMinFilename = filename.replace(/\.min(\.\w+)$/, "$1");
return production
? nonMinFilename.replace(/(\.\w+)$/, ".min$1")
: nonMinFilename;
}