| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import alias from '@rollup/plugin-alias'; |
| 9 | import cjs from '@rollup/plugin-commonjs'; |
| 10 | import nodeResolve from '@rollup/plugin-node-resolve'; |
| 11 | import replace from '@rollup/plugin-replace'; |
| 12 | import path from 'node:path'; |
| 13 | import {fileURLToPath} from 'node:url'; |
| 14 | import esbuild from 'rollup-plugin-esbuild'; |
| 15 | |
| 16 | // eslint-disable-next-line no-undef |
| 17 | const isProduction = process.env.NODE_ENV === 'production'; |
| 18 | |
| 19 | const filePath = fileURLToPath(import.meta.url); |
| 20 | const __dirname = path.dirname(filePath); |
| 21 | const projectRootDir = path.dirname(__dirname); |
| 22 | |
| 23 | const customResolver = nodeResolve({ |
| 24 | extensions: ['.ts', '.mjs', '.js', '.jsx', '.json', '.sass', '.scss'], |
| 25 | }); |
| 26 | |
| 27 | export default (async () => { |
| 28 | /** @type {import('rollup').RollupOptions} */ |
| 29 | return { |
| 30 | input: { |
| 31 | child: './proxy/child.ts', |
| 32 | 'run-proxy': './proxy/run-proxy.ts', |
| 33 | server: './proxy/server.ts', |
| 34 | }, |
| 35 | output: { |
| 36 | format: 'cjs', |
| 37 | dir: 'dist', |
| 38 | paths: id => id, |
| 39 | sourcemap: true, |
| 40 | }, |
| 41 | external: ['ws'], |
| 42 | plugins: [ |
| 43 | replace({ |
| 44 | 'process.env.NODE_ENV': isProduction ? '"production"' : '"development"', |
| 45 | preventAssignment: true, |
| 46 | }), |
| 47 | // Support importing from `isl` and `shared` inside `isl-server` |
| 48 | alias({ |
| 49 | entries: [ |
| 50 | { |
| 51 | find: /^isl/, |
| 52 | replacement: path.resolve(projectRootDir, 'isl'), |
| 53 | }, |
| 54 | { |
| 55 | find: /^shared/, |
| 56 | replacement: path.resolve(projectRootDir, 'shared'), |
| 57 | }, |
| 58 | ], |
| 59 | customResolver, |
| 60 | }), |
| 61 | esbuild(), |
| 62 | nodeResolve({preferBuiltins: true, moduleDirectories: ['..', 'node_modules']}), |
| 63 | cjs(), |
| 64 | isProduction && (await import('@rollup/plugin-terser')).default(), |
| 65 | ], |
| 66 | }; |
| 67 | })(); |
| 68 | |