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