/ packages / string-templates / rollup.config.js
rollup.config.js
 1  import commonjs from "@rollup/plugin-commonjs"
 2  import resolve from "@rollup/plugin-node-resolve"
 3  import json from "@rollup/plugin-json"
 4  import typescript from "@rollup/plugin-typescript"
 5  import polyfillNode from "rollup-plugin-polyfill-node"
 6  import inject from "@rollup/plugin-inject"
 7  import { terser } from "rollup-plugin-terser"
 8  
 9  const production = !process.env.ROLLUP_WATCH
10  
11  const config = (input, outputFile, format) => ({
12    input,
13    output: {
14      sourcemap: !production,
15      format,
16      file: outputFile,
17    },
18    onwarn(warning, warn) {
19      if (warning.code === "EVAL") {
20        return
21      }
22      warn(warning)
23    },
24    plugins: [
25      typescript({
26        moduleResolution: "node",
27      }),
28      polyfillNode(),
29      resolve({
30        preferBuiltins: true,
31        browser: true,
32      }),
33      commonjs(),
34      json(),
35      inject({ Buffer: ["buffer", "Buffer"], process: "process/browser" }),
36      production && terser(),
37    ],
38  })
39  
40  export default [
41    config("src/index.ts", "./dist/bundle.cjs", "cjs"),
42    config("src/index.ts", "./dist/bundle.mjs", "esm"),
43  ]