shareon/rollup.config.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

import buble from '@rollup/plugin-buble';
2020-07-31 12:54:51 -04:00
import consts from '@nickkaramoff/rollup-plugin-consts';
2020-06-26 10:51:13 -04:00
import license from 'rollup-plugin-license';
import strip from '@rollup/plugin-strip';
import { terser } from 'rollup-plugin-terser';
const { urlBuilderMap } = require('./src/networks');
2020-07-31 12:54:51 -04:00
2020-06-26 10:51:13 -04:00
const isDev = process.env.ROLLUP_WATCH || process.env.NODE_ENV === 'development';
const pkg = require('./package.json');
2020-07-26 08:17:16 -04:00
const outputDir = isDev ? './dev/' : './dist/';
2020-06-26 10:51:13 -04:00
const bannerText = `${pkg.name} v${pkg.version} by Nikita Karamov\n${pkg.homepage}`;
const plugins = [
2020-07-31 12:54:51 -04:00
consts({
urlBuilderMap,
}),
(!isDev) && strip({
2020-06-26 10:51:13 -04:00
debugger: true,
include: ['**/*.js'],
2020-06-26 10:51:13 -04:00
functions: ['console.log', 'console.debug', 'assert.*'],
sourceMap: false,
}),
(!isDev) && license({
2020-06-26 10:51:13 -04:00
banner: {
commentStyle: 'ignored',
content: bannerText,
},
}),
(!isDev) && buble({ transforms: { modules: false } }),
];
2020-06-26 10:51:13 -04:00
const getOutput = (baseDir) => {
2020-07-30 06:18:27 -04:00
const defaultParameters = {
name: pkg.name,
exports: 'default',
};
2020-07-23 05:13:21 -04:00
return [
{
2020-07-30 06:18:27 -04:00
...defaultParameters,
2020-07-26 08:17:16 -04:00
format: 'iife',
file: `${baseDir}${pkg.name}${isDev ? '' : '.min'}.js`,
plugins: isDev ? [] : [terser({ output: { comments: false } })],
},
(!isDev) && {
2020-07-30 06:18:27 -04:00
...defaultParameters,
2020-07-26 08:17:16 -04:00
format: 'cjs',
file: `${baseDir}${pkg.name}.cjs`,
},
(!isDev) && {
2020-07-30 06:18:27 -04:00
...defaultParameters,
format: 'esm',
2020-07-26 08:17:16 -04:00
file: `${baseDir}${pkg.name}.mjs`,
},
];
};
const config = [
{
2020-07-31 12:18:17 -04:00
input: './src/autoinit.js',
output: getOutput(`${outputDir}`),
plugins,
},
{
2020-07-31 12:18:17 -04:00
input: './src/shareon.js',
output: getOutput(`${outputDir}noinit/`),
plugins,
},
];
2020-06-26 10:51:13 -04:00
2020-07-23 05:13:21 -04:00
export default config;