| 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 importJson from '@rollup/plugin-json'; |
| 11 | import nodeResolve from '@rollup/plugin-node-resolve'; |
| 12 | import replace from '@rollup/plugin-replace'; |
| 13 | import path from 'node:path'; |
| 14 | import {fileURLToPath} from 'node:url'; |
| 15 | import esbuild from 'rollup-plugin-esbuild'; |
| 16 | |
| 17 | // eslint-disable-next-line no-undef |
| 18 | const isProduction = process.env.NODE_ENV === 'production'; |
| 19 | |
| 20 | const filePath = fileURLToPath(import.meta.url); |
| 21 | const __dirname = path.dirname(filePath); |
| 22 | const projectRootDir = path.dirname(__dirname); |
| 23 | |
| 24 | const customResolver = nodeResolve({ |
| 25 | extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json', '.sass', '.scss'], |
| 26 | }); |
| 27 | |
| 28 | export default (async () => { |
| 29 | /** @type {import('rollup').RollupOptions} */ |
| 30 | return { |
| 31 | input: './extension/extension.ts', |
| 32 | output: { |
| 33 | format: 'cjs', |
| 34 | dir: 'dist', |
| 35 | paths: id => id, |
| 36 | sourcemap: true, |
| 37 | }, |
| 38 | external: ['ws', 'vscode'], |
| 39 | plugins: [ |
| 40 | replace({ |
| 41 | 'process.env.NODE_ENV': isProduction ? '"production"' : '"development"', |
| 42 | preventAssignment: true, |
| 43 | }), |
| 44 | // Support importing from `isl` and `shared` inside `vscode` |
| 45 | alias({ |
| 46 | entries: [ |
| 47 | { |
| 48 | find: /^isl/, |
| 49 | replacement: path.resolve(projectRootDir, 'isl'), |
| 50 | }, |
| 51 | { |
| 52 | find: /^shared/, |
| 53 | replacement: path.resolve(projectRootDir, 'shared'), |
| 54 | }, |
| 55 | ], |
| 56 | customResolver, |
| 57 | }), |
| 58 | esbuild(), |
| 59 | nodeResolve({preferBuiltins: true, moduleDirectories: ['..', 'node_modules']}), |
| 60 | cjs(), |
| 61 | importJson(), |
| 62 | isProduction && (await import('@rollup/plugin-terser')).default(), |
| 63 | ], |
| 64 | }; |
| 65 | })(); |
| 66 | |