import resolve from "@rollup/plugin-node-resolve"; import replace from "@rollup/plugin-replace"; import commonjs from "@rollup/plugin-commonjs"; import json from "@rollup/plugin-json"; import typescript from "@rollup/plugin-typescript"; import svelte from "rollup-plugin-svelte"; import babel from "@rollup/plugin-babel"; import { terser } from "rollup-plugin-terser"; import config from "sapper/config/rollup"; import alias from "@rollup/plugin-alias"; import * as path from "path"; import pkg from "./package.json"; const preprocess = [ // eslint-disable-next-line global-require require("./svelte.config").preprocess, // You could have more preprocessors, like MDsveX ]; const mode = process.env.NODE_ENV; const dev = mode === "development"; const sourcemap = dev ? "inline" : false; const legacy = !!process.env.SAPPER_LEGACY_BUILD; const IGNORED_MESSAGES = [ "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification", "Circular dependency: node_modules", ]; const IGNORED_CODES = [ "THIS_IS_UNDEFINED", ]; const warningIsIgnored = (warning) => IGNORED_MESSAGES.some((m) => warning.message.includes(m)) || IGNORED_CODES.indexOf(warning.code) >= 0; // Workaround for https://github.com/sveltejs/sapper/issues/1221 const onwarn = (warning, _onwarn) => (warning.code === "CIRCULAR_DEPENDENCY" && /[/\\]@sapper[/\\]/.test(warning.message)) || warningIsIgnored(warning) || console.warn(warning.toString()); export default { client: { input: config.client.input().replace(/\.js$/, ".ts"), output: { ...config.client.output(), sourcemap }, external: (id) => id.includes("@babel/runtime"), plugins: [ replace({ "process.browser": true, "process.env.NODE_ENV": JSON.stringify(mode), }), svelte({ compilerOptions: { dev, hydratable: true, }, preprocess, }), resolve({ browser: true, dedupe: ["svelte"], }), alias({ entries: [ { find: "@shared", replacement: path.join(__dirname, "../shared/lib/src") }, ], }), commonjs(), typescript(), json(), legacy && babel({ extensions: [".js", ".mjs", ".html", ".svelte"], babelHelpers: "runtime", exclude: ["node_modules/**"], presets: ["@babel/preset-env"], plugins: [ "@babel/plugin-syntax-dynamic-import", ["@babel/plugin-transform-runtime", { useESModules: true, }], ], }), !dev && terser({ module: true, }), ], preserveEntrySignatures: false, onwarn, }, server: { input: { server: config.server.input().server.replace(/\.js$/, ".ts") }, output: { ...config.server.output(), sourcemap, interop: "default", }, plugins: [ replace({ "process.browser": false, "process.env.NODE_ENV": JSON.stringify(mode), "module.require": "require", }), svelte({ emitCss: false, compilerOptions: { generate: "ssr", dev, hydratable: true, }, preprocess, }), resolve({ dedupe: ["svelte"], }), alias({ entries: [ { find: "@shared", replacement: path.join(__dirname, "../shared/lib/src") }, ], }), typescript(), commonjs({ include: ["../shared/lib/**"], }), json(), ], external: Object.keys(pkg.dependencies).concat( require("module").builtinModules || Object.keys(process.binding("natives")), // eslint-disable-line global-require ).concat(/rpc_ts/), preserveEntrySignatures: "strict", onwarn, }, };