Skip to content

Commit

Permalink
Format and preventAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Valgeir Bjornsson committed Jun 8, 2021
1 parent 619eab7 commit 52f94d6
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
// rollup.config.js
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';
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')
const esbrowserslist = fs
.readFileSync("./.browserslistrc")
.toString()
.split('\n')
.filter((entry) => entry && entry.substring(0, 2) !== 'ie');
.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 babelPresetEnvConfig = require("../babel.config").presets.filter(
entry => entry[0] === "@babel/preset-env",
)[0][1];

const argv = minimist(process.argv.slice(2));

const projectRoot = path.resolve(__dirname, '..');
const projectRoot = path.resolve(__dirname, "..");

const baseConfig = {
input: 'src/entry.js',
input: "src/entry.js",
plugins: {
preVue: [
alias({
entries: [
{
find: '@',
replacement: `${path.resolve(projectRoot, 'src')}`,
find: "@",
replacement: `${path.resolve(projectRoot, "src")}`,
},
],
}),
],
replace: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
vue: {
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
},
vue: {},
postVue: [
resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
}),
// Process only `<style module>` blocks.
PostCSS({
modules: {
generateScopedName: '[local]___[hash:base64:5]',
generateScopedName: "[local]___[hash:base64:5]",
},
include: /&module=.*\.css$/,
}),
Expand All @@ -59,9 +61,9 @@ const baseConfig = {
commonjs(),
],
babel: {
exclude: 'node_modules/**',
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
babelHelpers: 'bundled',
exclude: "node_modules/**",
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
babelHelpers: "bundled",
},
},
};
Expand All @@ -71,28 +73,28 @@ const baseConfig = {
const external = [
// list external dependencies, exactly the way it is written in the import statement.
// eg. 'jquery'
'vue',
"vue",
];

// 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: '$'
vue: 'Vue',
vue: "Vue",
};

// Customize configs for individual targets
const buildFormats = [];
if (!argv.format || argv.format === 'es') {
if (!argv.format || argv.format === "es") {
const esConfig = {
...baseConfig,
input: 'src/entry.esm.js',
input: "src/entry.esm.js",
external,
output: {
file: 'dist/popper.esm.js',
format: 'esm',
exports: 'named',
file: "dist/popper.esm.js",
format: "esm",
exports: "named",
},
plugins: [
replace(baseConfig.plugins.replace),
Expand All @@ -103,7 +105,7 @@ if (!argv.format || argv.format === 'es') {
...baseConfig.plugins.babel,
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
...babelPresetEnvConfig,
targets: esbrowserslist,
Expand All @@ -116,16 +118,16 @@ if (!argv.format || argv.format === 'es') {
buildFormats.push(esConfig);
}

if (!argv.format || argv.format === 'cjs') {
if (!argv.format || argv.format === "cjs") {
const umdConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/popper.ssr.js',
format: 'cjs',
name: 'Popper',
exports: 'auto',
file: "dist/popper.ssr.js",
format: "cjs",
name: "Popper",
exports: "auto",
globals,
},
plugins: [
Expand All @@ -139,16 +141,16 @@ if (!argv.format || argv.format === 'cjs') {
buildFormats.push(umdConfig);
}

if (!argv.format || argv.format === 'iife') {
if (!argv.format || argv.format === "iife") {
const unpkgConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/popper.min.js',
format: 'iife',
name: 'Popper',
exports: 'auto',
file: "dist/popper.min.js",
format: "iife",
name: "Popper",
exports: "auto",
globals,
},
plugins: [
Expand Down

0 comments on commit 52f94d6

Please sign in to comment.