|
1 | | -const { defineConfig } = require('rollup'); |
2 | | -const json = require('@rollup/plugin-json'); |
3 | | -const { nodeResolve } = require('@rollup/plugin-node-resolve'); |
4 | | -const commonjs = require('@rollup/plugin-commonjs'); |
5 | | -const { babel } = require('@rollup/plugin-babel'); |
6 | | -const terser = require('@rollup/plugin-terser'); |
7 | | -const replace = require('@rollup/plugin-replace'); |
8 | | -const babelConfig = require('../../templates/babel.config'); |
9 | | -const { |
10 | | - getName, |
11 | | - resolvePath, |
12 | | - getOutputFileName, |
13 | | - env, |
14 | | - getInputProps, |
15 | | - resolveOutputFields, |
16 | | - externalize, |
17 | | - opts, |
18 | | - check, |
19 | | - updateArgs, |
20 | | - getLogger, |
21 | | - getResource, |
22 | | -} = require('../../utils'); |
23 | | -const { fileSize } = require('../../plugins'); |
24 | | -const { MSG_BABELRC, configTypes, DEV } = require('../../constants'); |
| 1 | +const rollupConfig = require('../../templates/rollup.config'); |
25 | 2 |
|
26 | | -const commonOutputConfig = { |
27 | | - name: getName(), |
28 | | - exports: 'named', |
29 | | - sourcemap: true, |
30 | | -}; |
31 | | - |
32 | | -const { main: pjMain, module: pjModule } = resolveOutputFields(); |
33 | | - |
34 | | -const defaultConfig = defineConfig({ |
35 | | - output: [ |
36 | | - { |
37 | | - file: getOutputFileName(pjModule, true), |
38 | | - format: 'es', |
39 | | - }, |
40 | | - { |
41 | | - file: getOutputFileName(pjMain, true), |
42 | | - format: 'cjs', |
43 | | - }, |
44 | | - { |
45 | | - file: getOutputFileName(pjModule), |
46 | | - format: 'es', |
47 | | - }, |
48 | | - { |
49 | | - file: getOutputFileName(pjMain), |
50 | | - format: 'cjs', |
51 | | - }, |
52 | | - ], |
53 | | - plugins: [ |
54 | | - replace({ |
55 | | - values: env(), |
56 | | - preventAssignment: true, |
57 | | - objectGuards: true, |
58 | | - }), |
59 | | - json(), |
60 | | - nodeResolve(), |
61 | | - commonjs({ |
62 | | - include: 'node_modules/**', |
63 | | - extensions: ['.js', '.ts'], |
64 | | - }), |
65 | | - ], |
66 | | - external: externalize(), |
67 | | -}); |
68 | | - |
69 | | -module.exports = async (args, lgr) => { |
70 | | - const logger = getLogger(args, lgr); |
71 | | - const { input, typescript, react, preact } = getInputProps(args, logger); |
72 | | - const finalArgs = updateArgs(args, { typescript, react, preact }); |
73 | | - const babelFile = await check(configTypes.BABEL); |
74 | | - const babelrc = !!babelFile; |
75 | | - if (babelrc) { |
76 | | - logger.log(MSG_BABELRC(babelFile)); |
77 | | - } |
78 | | - const { configFile } = finalArgs; |
79 | | - const confFunc = getResource(configFile); |
80 | | - let finalConfig = Object.assign(defaultConfig, { |
81 | | - input, |
82 | | - }); |
83 | | - finalConfig.output = defaultConfig.output.map((outConf) => { |
84 | | - const isDev = DEV.test(outConf.file); |
85 | | - Object.assign(outConf, commonOutputConfig, { |
86 | | - sourcemap: isDev, |
87 | | - plugins: opts(!isDev, [terser()]), |
88 | | - }); |
89 | | - return outConf; |
90 | | - }); |
91 | | - finalConfig.plugins.push( |
92 | | - babel({ |
93 | | - babelrc, |
94 | | - exclude: 'node_modules/**', |
95 | | - extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.es6', '.es'], |
96 | | - babelHelpers: 'runtime', |
97 | | - skipPreflightCheck: true, |
98 | | - ...(babelrc ? {} : babelConfig(finalArgs)), |
99 | | - }), |
100 | | - fileSize(args, logger) |
101 | | - ); |
102 | | - try { |
103 | | - if (typeof confFunc === 'function') { |
104 | | - finalConfig = await Promise.resolve(confFunc(defaultConfig)); |
105 | | - } |
106 | | - } catch (e) { |
107 | | - logger.verbose(e); |
108 | | - } |
109 | | - return finalConfig; |
| 3 | +module.exports = async (args) => { |
| 4 | + return await rollupConfig(args); |
110 | 5 | }; |
0 commit comments