shareon-pulsanti-condivisio.../rollup.config.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
2.5 KiB
JavaScript
Raw Normal View History

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