1 | 'use strict';
|
2 | const typescript = require('rollup-plugin-typescript2');
|
3 | const { terser } = require('rollup-plugin-terser');
|
4 | const commonjs = require('@rollup/plugin-commonjs');
|
5 | const json = require('@rollup/plugin-json');
|
6 | const path = require('path');
|
7 | const fs = require('fs');
|
8 |
|
9 | const BASE_PATH = process.cwd();
|
10 |
|
11 | const getConfigFile = name => {
|
12 | const filePath = path.resolve(BASE_PATH, name);
|
13 | if (fs.existsSync(path.resolve(BASE_PATH, name))) {
|
14 | return filePath;
|
15 | }
|
16 |
|
17 | return require.resolve(`@stoplight/scripts/${name}`);
|
18 | };
|
19 |
|
20 | const plugins = () =>
|
21 | [
|
22 | typescript({
|
23 | tsconfig: getConfigFile('tsconfig.build.json'),
|
24 | useTsconfigDeclarationDir: true,
|
25 | }),
|
26 | process.env.MINIFY ? terser() : null,
|
27 | ].filter(Boolean);
|
28 |
|
29 | const packageJson = JSON.parse(fs.readFileSync(path.resolve(BASE_PATH, 'package.json'), { encoding: 'utf-8' }));
|
30 | const dependencies = [
|
31 | ...Object.keys(packageJson.dependencies || {}),
|
32 | ...Object.keys(packageJson.peerDependencies || {}),
|
33 | ];
|
34 | const external = module => dependencies.some(dep => module === dep || module.startsWith(`${dep}/`));
|
35 |
|
36 | module.exports = [
|
37 | {
|
38 | input: path.resolve(BASE_PATH, 'src/index.ts'),
|
39 | output: {
|
40 | entryFileNames: '[name].js',
|
41 | dir: path.resolve(BASE_PATH, 'dist'),
|
42 | format: 'cjs',
|
43 | },
|
44 | plugins: [json(), commonjs(), ...plugins()],
|
45 | external
|
46 | },
|
47 | {
|
48 | input: path.resolve(BASE_PATH, 'src/index.ts'),
|
49 | output: {
|
50 | entryFileNames: '[name].mjs',
|
51 | dir: path.resolve(BASE_PATH, 'dist'),
|
52 | format: 'esm',
|
53 | },
|
54 | plugins: plugins(),
|
55 | external,
|
56 | },
|
57 | ];
|