Newer
Older
import fs from "fs";
import path from "path";
import vue from "rollup-plugin-vue";
import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import babel from "@rollup/plugin-babel";
import PostCSS from "rollup-plugin-postcss";
import { terser } from "rollup-plugin-terser";
import minimist from "minimist";
// Get browserslist config and remove ie from es build targets
const esbrowserslist = fs
.readFileSync("./.browserslistrc")
.split("\n")
.filter((entry) => entry && entry.substring(0, 2) !== "ie");
// Extract babel preset-env config, to combine with esbrowserslist
const babelPresetEnvConfig = require("../babel.config").presets.filter(
(entry) => entry[0] === "@babel/preset-env"
)[0][1];
const argv = minimist(process.argv.slice(2));
plugins: {
preVue: [
alias({
entries: [
{
find: "@",
replacement: `${path.resolve(projectRoot, "src")}`,
"process.env.NODE_ENV": JSON.stringify("production"),
}),
// Process only `<style module>` blocks.
PostCSS({
modules: {
},
include: /&module=.*\.css$/,
}),
// Process all `<style>` blocks except `<style module>`.
PostCSS({ include: /(?<!&module=.*)\.css$/ }),
commonjs(),
],
babel: {
exclude: "node_modules/**",
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
babelHelpers: "bundled",
},
},
};
// ESM/UMD/IIFE shared settings: externals
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
const external = [
// list external dependencies, exactly the way it is written in the import statement.
// eg. 'jquery'
"bootstrap-icons",
"vue-currency-input",
"@baloise/vue-keycloak",
];
// UMD/IIFE shared settings: output.globals
// Refer to https://rollupjs.org/guide/en#output-globals for details
const globals = {
// Provide global variable names to replace your external imports
// eg. jquery: '$'
};
// Customize configs for individual targets
const buildFormats = [];
file: "dist/vue-bootstrap5-components.esm.js",
format: "esm",
exports: "named",
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel({
...baseConfig.plugins.babel,
presets: [
[
{
...babelPresetEnvConfig,
targets: esbrowserslist,
},
],
],
}),
],
};
buildFormats.push(esConfig);
}
const umdConfig = {
...baseConfig,
external,
output: {
compact: true,
file: "dist/vue-bootstrap5-components.ssr.js",
format: "cjs",
name: "VueBootstrap5Components",
exports: "auto",
globals,
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
],
};
buildFormats.push(umdConfig);
}
const unpkgConfig = {
...baseConfig,
external,
output: {
compact: true,
file: "dist/vue-bootstrap5-components.min.js",
format: "iife",
name: "VueBootstrap5Components",
exports: "auto",
globals,
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
terser({
output: {
ecma: 5,
},
}),
],
};
buildFormats.push(unpkgConfig);
}
// Export config
export default buildFormats;