2020-06-26 10:51:13 -04:00
|
|
|
import license from 'rollup-plugin-license';
|
|
|
|
import postcss from 'rollup-plugin-postcss';
|
|
|
|
import postcssPluginBanner from 'postcss-banner';
|
|
|
|
import postcssPluginCssnano from 'cssnano';
|
|
|
|
import strip from '@rollup/plugin-strip';
|
|
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
import typescript from '@rollup/plugin-typescript';
|
|
|
|
|
|
|
|
const isDev = process.env.ROLLUP_WATCH || process.env.NODE_ENV === 'development';
|
|
|
|
|
|
|
|
const pkg = require('./package.json');
|
|
|
|
|
|
|
|
const inputFile = './src/index.ts';
|
2020-06-26 11:32:37 -04:00
|
|
|
const outputDir = isDev ? './dev/' : './dist/';
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2020-07-16 06:02:07 -04:00
|
|
|
const bannerText = `${pkg.name} v${pkg.version} by Nikita Karamov\n${pkg.homepage}`;
|
2020-06-26 10:51:13 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PLUGINS
|
|
|
|
*/
|
|
|
|
|
|
|
|
const plugins = [];
|
|
|
|
|
|
|
|
plugins.push(typescript());
|
|
|
|
|
|
|
|
if (!isDev) {
|
|
|
|
plugins.push(strip({
|
|
|
|
debugger: true,
|
|
|
|
include: ['**/*.js', '**/*.ts'],
|
|
|
|
functions: ['console.log', 'console.debug', 'assert.*'],
|
|
|
|
sourceMap: false,
|
|
|
|
}));
|
|
|
|
|
|
|
|
plugins.push(license({
|
|
|
|
banner: {
|
|
|
|
commentStyle: 'ignored',
|
|
|
|
content: bannerText,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins.push(postcss({
|
2020-07-16 06:02:07 -04:00
|
|
|
extract: `${pkg.name}.min.css`,
|
2020-06-26 10:51:13 -04:00
|
|
|
plugins: [
|
|
|
|
(!isDev) && postcssPluginCssnano({
|
|
|
|
preset: 'default',
|
|
|
|
}),
|
|
|
|
postcssPluginBanner({
|
|
|
|
banner: bannerText,
|
|
|
|
important: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OUTPUTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
const output = [];
|
|
|
|
|
|
|
|
if (isDev) {
|
|
|
|
output.push({
|
2020-07-16 06:02:07 -04:00
|
|
|
name: pkg.name,
|
2020-06-26 10:51:13 -04:00
|
|
|
format: 'iife',
|
2020-07-16 06:02:07 -04:00
|
|
|
file: `${outputDir}${pkg.name}.js`,
|
2020-06-26 10:51:13 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
output.push({
|
2020-07-16 06:02:07 -04:00
|
|
|
name: pkg.name,
|
2020-06-26 10:51:13 -04:00
|
|
|
format: 'cjs',
|
2020-07-16 06:02:07 -04:00
|
|
|
file: `${outputDir}${pkg.name}.cjs`,
|
2020-06-26 10:51:13 -04:00
|
|
|
});
|
2020-06-26 11:17:49 -04:00
|
|
|
output.push({
|
2020-07-16 06:02:07 -04:00
|
|
|
name: pkg.name,
|
2020-06-26 11:17:49 -04:00
|
|
|
format: 'esm',
|
2020-07-16 06:02:07 -04:00
|
|
|
file: `${outputDir}${pkg.name}.mjs`,
|
2020-06-26 11:17:49 -04:00
|
|
|
});
|
2020-06-26 10:51:13 -04:00
|
|
|
output.push({
|
2020-07-16 06:02:07 -04:00
|
|
|
name: pkg.name,
|
2020-06-26 10:51:13 -04:00
|
|
|
format: 'iife',
|
2020-07-16 06:02:07 -04:00
|
|
|
file: `${outputDir}${pkg.name}.min.js`,
|
2020-06-26 10:51:13 -04:00
|
|
|
plugins: [terser({ output: { comments: false } })],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EXPORT
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default {
|
|
|
|
input: inputFile,
|
|
|
|
output,
|
|
|
|
plugins,
|
|
|
|
};
|