addons/isl-server/rollup.config.mjsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import alias from '@rollup/plugin-alias';
b69ab319import cjs from '@rollup/plugin-commonjs';
b69ab3110import nodeResolve from '@rollup/plugin-node-resolve';
b69ab3111import replace from '@rollup/plugin-replace';
b69ab3112import path from 'node:path';
b69ab3113import {fileURLToPath} from 'node:url';
b69ab3114import esbuild from 'rollup-plugin-esbuild';
b69ab3115
b69ab3116// eslint-disable-next-line no-undef
b69ab3117const isProduction = process.env.NODE_ENV === 'production';
b69ab3118
b69ab3119const filePath = fileURLToPath(import.meta.url);
b69ab3120const __dirname = path.dirname(filePath);
b69ab3121const projectRootDir = path.dirname(__dirname);
b69ab3122
b69ab3123const customResolver = nodeResolve({
b69ab3124 extensions: ['.ts', '.mjs', '.js', '.jsx', '.json', '.sass', '.scss'],
b69ab3125});
b69ab3126
b69ab3127export default (async () => {
b69ab3128 /** @type {import('rollup').RollupOptions} */
b69ab3129 return {
b69ab3130 input: {
b69ab3131 child: './proxy/child.ts',
b69ab3132 'run-proxy': './proxy/run-proxy.ts',
b69ab3133 server: './proxy/server.ts',
b69ab3134 },
b69ab3135 output: {
b69ab3136 format: 'cjs',
b69ab3137 dir: 'dist',
b69ab3138 paths: id => id,
b69ab3139 sourcemap: true,
b69ab3140 },
b69ab3141 external: ['ws'],
b69ab3142 plugins: [
b69ab3143 replace({
b69ab3144 'process.env.NODE_ENV': isProduction ? '"production"' : '"development"',
b69ab3145 preventAssignment: true,
b69ab3146 }),
b69ab3147 // Support importing from `isl` and `shared` inside `isl-server`
b69ab3148 alias({
b69ab3149 entries: [
b69ab3150 {
b69ab3151 find: /^isl/,
b69ab3152 replacement: path.resolve(projectRootDir, 'isl'),
b69ab3153 },
b69ab3154 {
b69ab3155 find: /^shared/,
b69ab3156 replacement: path.resolve(projectRootDir, 'shared'),
b69ab3157 },
b69ab3158 ],
b69ab3159 customResolver,
b69ab3160 }),
b69ab3161 esbuild(),
b69ab3162 nodeResolve({preferBuiltins: true, moduleDirectories: ['..', 'node_modules']}),
b69ab3163 cjs(),
b69ab3164 isProduction && (await import('@rollup/plugin-terser')).default(),
b69ab3165 ],
b69ab3166 };
b69ab3167})();