2021-01-17 14:32:59 -05:00
|
|
|
import { join, resolve } from 'path';
|
2021-01-17 03:22:20 -05:00
|
|
|
|
2020-09-18 13:40:26 -04:00
|
|
|
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 strip from '@rollup/plugin-strip';
|
2021-01-17 14:32:59 -05:00
|
|
|
import postcss from 'rollup-plugin-postcss';
|
2020-06-26 10:51:13 -04:00
|
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
|
2021-01-17 14:32:59 -05:00
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const banner = require('postcss-banner');
|
|
|
|
const calc = require('postcss-calc');
|
|
|
|
const cssnano = require('cssnano');
|
|
|
|
const cssVariables = require('postcss-css-variables');
|
|
|
|
const mixins = require('postcss-mixins');
|
|
|
|
|
|
|
|
const networks = require('./src/networksMixin');
|
2020-09-18 13:40:26 -04:00
|
|
|
const { urlBuilderMap } = require('./src/networks');
|
2021-01-17 14:32:59 -05:00
|
|
|
const pkg = require('./package.json');
|
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';
|
2021-01-17 14:32:59 -05:00
|
|
|
const outputDir = resolve('.', 'dist');
|
|
|
|
const bannerText = `${pkg.name} v${pkg.version}`;
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2021-01-17 14:32:59 -05:00
|
|
|
const postcssPlugins = [
|
|
|
|
mixins({
|
|
|
|
mixins: {
|
|
|
|
networks,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cssVariables,
|
|
|
|
calc,
|
|
|
|
];
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2021-01-17 14:32:59 -05:00
|
|
|
if (!isDev) {
|
|
|
|
postcssPlugins.push(
|
|
|
|
cssnano({
|
|
|
|
preset: 'default',
|
|
|
|
}),
|
|
|
|
autoprefixer(),
|
|
|
|
banner({
|
|
|
|
banner: bannerText,
|
|
|
|
important: true,
|
|
|
|
inline: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2021-01-17 14:32:59 -05:00
|
|
|
const getPlugins = (css) => [
|
2020-07-31 12:54:51 -04:00
|
|
|
consts({
|
|
|
|
urlBuilderMap,
|
|
|
|
}),
|
2021-01-17 14:32:59 -05:00
|
|
|
css && postcss({
|
|
|
|
extract: resolve(join(outputDir, 'shareon.min.css')),
|
|
|
|
plugins: postcssPlugins,
|
|
|
|
}),
|
2020-09-18 13:40:26 -04:00
|
|
|
(!isDev) && strip({
|
2020-06-26 10:51:13 -04:00
|
|
|
debugger: true,
|
2020-09-18 13:40:26 -04:00
|
|
|
include: ['**/*.js'],
|
2020-06-26 10:51:13 -04:00
|
|
|
functions: ['console.log', 'console.debug', 'assert.*'],
|
|
|
|
sourceMap: false,
|
2020-09-18 13:40:26 -04:00
|
|
|
}),
|
2021-01-17 03:22:20 -05:00
|
|
|
(!isDev) && buble({
|
|
|
|
transforms: {
|
|
|
|
modules: false,
|
2020-06-26 10:51:13 -04:00
|
|
|
},
|
2020-09-18 13:40:26 -04:00
|
|
|
}),
|
|
|
|
];
|
2020-06-26 10:51:13 -04:00
|
|
|
|
2020-09-18 13:40:26 -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
|
|
|
|
2020-09-18 13:40:26 -04:00
|
|
|
return [
|
|
|
|
{
|
2020-07-30 06:18:27 -04:00
|
|
|
...defaultParameters,
|
2020-07-26 08:17:16 -04:00
|
|
|
format: 'iife',
|
2021-01-17 03:22:20 -05:00
|
|
|
file: join(baseDir, `${pkg.name}${isDev ? '' : '.min'}.js`),
|
|
|
|
plugins: isDev ? [] : [terser({ output: { comments: /^!/ } })],
|
2021-01-17 14:32:59 -05:00
|
|
|
banner: `/*! ${bannerText} */`,
|
2020-09-18 13:40:26 -04:00
|
|
|
},
|
|
|
|
(!isDev) && {
|
2020-07-30 06:18:27 -04:00
|
|
|
...defaultParameters,
|
2020-07-26 08:17:16 -04:00
|
|
|
format: 'cjs',
|
2021-01-17 03:22:20 -05:00
|
|
|
file: join(baseDir, `${pkg.name}.cjs`),
|
2021-01-17 14:32:59 -05:00
|
|
|
banner: `/*! ${bannerText} */`,
|
2020-09-18 13:40:26 -04:00
|
|
|
},
|
|
|
|
(!isDev) && {
|
2020-07-30 06:18:27 -04:00
|
|
|
...defaultParameters,
|
2020-07-23 12:39:28 -04:00
|
|
|
format: 'esm',
|
2021-01-17 03:22:20 -05:00
|
|
|
file: join(baseDir, `${pkg.name}.mjs`),
|
2021-01-17 14:32:59 -05:00
|
|
|
banner: `/*! ${bannerText} */`,
|
2020-09-18 13:40:26 -04:00
|
|
|
},
|
|
|
|
];
|
2020-07-23 12:39:28 -04:00
|
|
|
};
|
|
|
|
|
2021-01-17 03:22:20 -05:00
|
|
|
export default [
|
2020-07-23 12:39:28 -04:00
|
|
|
{
|
2021-01-17 03:22:20 -05:00
|
|
|
input: join(__dirname, 'src', 'autoinit.js'),
|
|
|
|
output: getOutput(outputDir),
|
2021-01-17 14:32:59 -05:00
|
|
|
plugins: getPlugins(true),
|
2020-07-23 12:39:28 -04:00
|
|
|
},
|
|
|
|
{
|
2021-01-17 14:32:59 -05:00
|
|
|
input: join(__dirname, 'src', 'shareon.js'),
|
2021-01-17 03:22:20 -05:00
|
|
|
output: getOutput(join(outputDir, 'noinit')),
|
2021-01-17 14:32:59 -05:00
|
|
|
plugins: getPlugins(false),
|
2020-07-23 12:39:28 -04:00
|
|
|
},
|
|
|
|
];
|