shareon/rollup/plugins.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-29 18:20:12 -04:00
import path from 'path';
import postcssPluginBanner from 'postcss-banner';
2020-03-25 13:53:00 -04:00
import postcssPluginCssnano from 'cssnano';
import rollupPluginLicense from 'rollup-plugin-license';
2020-03-25 13:53:00 -04:00
import rollupPluginPostcss from 'rollup-plugin-postcss';
2020-03-25 12:44:11 -04:00
import rollupPluginStrip from '@rollup/plugin-strip';
import { terser as rollupPluginTerser } from 'rollup-plugin-terser';
import rollupPluginTypescript from '@rollup/plugin-typescript';
2020-03-29 18:20:12 -04:00
const pkg = require(path.join(process.cwd(), 'package.json'));
const bannerText = `${pkg.name} v${pkg.version} by Nikita Karamov
${pkg.homepage}`;
export const license = () => rollupPluginLicense({
banner: {
commentStyle: 'ignored',
2020-03-29 18:20:12 -04:00
content: bannerText
}
});
2020-03-25 14:09:56 -04:00
/**
* @param {boolean|string} file
* @param {boolean} minify
*/
export const postcss = (file = true, minify) => rollupPluginPostcss({
extract: file,
2020-03-25 13:53:00 -04:00
plugins: [
minify && postcssPluginCssnano({
preset: 'default',
2020-03-29 18:20:12 -04:00
}),
postcssPluginBanner({
banner: bannerText,
important: true
2020-03-25 13:53:00 -04:00
})
],
});
2020-03-25 13:53:00 -04:00
2020-03-25 12:44:11 -04:00
export const strip = () => rollupPluginStrip({
debugger: true,
2020-03-25 14:09:56 -04:00
include: ['**/*.js', '**/*.ts'],
functions: ['console.log', 'console.debug', 'assert.*'],
2020-03-25 12:44:11 -04:00
sourceMap: false,
});
export const terser = () => rollupPluginTerser({
output: {
comments: false,
ecma: 5,
},
});
export const typescript = () => rollupPluginTypescript();