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');
|
|
|
|
|
2020-06-26 11:32:37 -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}`;
|
|
|
|
|
2020-07-23 12:39:28 -04:00
|
|
|
/**
|
|
|
|
* Plugins to build the project
|
|
|
|
*
|
|
|
|
* @type {Plugin[]}
|
2020-06-26 10:51:13 -04:00
|
|
|
*/
|
2020-07-23 12:39:28 -04:00
|
|
|
const plugins = [
|
|
|
|
typescript(),
|
|
|
|
];
|
2020-06-26 10:51:13 -04:00
|
|
|
|
|
|
|
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-04 16:10:58 -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,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
|
2020-07-23 12:39:28 -04:00
|
|
|
/**
|
|
|
|
* @typedef {import('rollup').OutputOptions} OutputOptions
|
2020-06-26 10:51:13 -04:00
|
|
|
*/
|
|
|
|
|
2020-07-23 12:39:28 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} baseDir base directory for the output files
|
|
|
|
* @return {OutputOptions[]} array of outputs
|
|
|
|
*/
|
|
|
|
const getOutputs = (baseDir) => {
|
|
|
|
const result = [];
|
2020-07-23 05:13:21 -04:00
|
|
|
|
2020-07-23 12:39:28 -04:00
|
|
|
if (isDev) {
|
|
|
|
result.push({
|
2020-07-23 05:13:21 -04:00
|
|
|
name: pkg.name,
|
|
|
|
format: 'iife',
|
2020-07-23 14:00:31 -04:00
|
|
|
file: `${baseDir}index.js`,
|
2020-07-23 12:39:28 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
result.push({
|
|
|
|
name: pkg.name,
|
|
|
|
format: 'cjs',
|
2020-07-23 14:00:31 -04:00
|
|
|
file: `${baseDir}index.cjs`,
|
2020-07-23 12:39:28 -04:00
|
|
|
});
|
|
|
|
result.push({
|
|
|
|
name: pkg.name,
|
|
|
|
format: 'esm',
|
2020-07-23 14:00:31 -04:00
|
|
|
file: `${baseDir}index.mjs`,
|
2020-07-23 12:39:28 -04:00
|
|
|
});
|
|
|
|
result.push({
|
|
|
|
name: pkg.name,
|
|
|
|
format: 'iife',
|
2020-07-23 14:00:31 -04:00
|
|
|
file: `${baseDir}index.min.js`,
|
2020-07-23 05:13:21 -04:00
|
|
|
plugins: [terser({ output: { comments: false } })],
|
2020-07-23 12:39:28 -04:00
|
|
|
});
|
|
|
|
}
|
2020-07-23 05:13:21 -04:00
|
|
|
|
2020-07-23 12:39:28 -04:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
const config = [
|
|
|
|
{
|
|
|
|
input: './src/autoinit.ts',
|
|
|
|
output: getOutputs(`${outputDir}`),
|
|
|
|
plugins,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: './src/shareon.ts',
|
|
|
|
output: getOutputs(`${outputDir}noinit/`),
|
|
|
|
plugins: plugins.slice(0, -1),
|
|
|
|
},
|
|
|
|
];
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2020-07-23 05:13:21 -04:00
|
|
|
export default config;
|