1 | import resolve from '@rollup/plugin-node-resolve';
|
2 | import commonjs from '@rollup/plugin-commonjs';
|
3 | import {terser} from "rollup-plugin-terser";
|
4 | import json from '@rollup/plugin-json';
|
5 | import { babel } from '@rollup/plugin-babel';
|
6 | import autoExternal from 'rollup-plugin-auto-external';
|
7 | import bundleSize from 'rollup-plugin-bundle-size'
|
8 | import path from 'path';
|
9 |
|
10 | const lib = require("./package.json");
|
11 | const outputFileName = 'axios';
|
12 | const name = "axios";
|
13 | const namedInput = './index.js';
|
14 | const defaultInput = './lib/axios.js';
|
15 |
|
16 | const buildConfig = ({es5, browser = true, minifiedVersion = true, ...config}) => {
|
17 | const {file} = config.output;
|
18 | const ext = path.extname(file);
|
19 | const basename = path.basename(file, ext);
|
20 | const extArr = ext.split('.');
|
21 | extArr.shift();
|
22 |
|
23 |
|
24 | const build = ({minified}) => ({
|
25 | input: namedInput,
|
26 | ...config,
|
27 | output: {
|
28 | ...config.output,
|
29 | file: `${path.dirname(file)}/${basename}.${(minified ? ['min', ...extArr] : extArr).join('.')}`
|
30 | },
|
31 | plugins: [
|
32 | json(),
|
33 | resolve({browser}),
|
34 | commonjs(),
|
35 | minified && terser(),
|
36 | minified && bundleSize(),
|
37 | ...(es5 ? [babel({
|
38 | babelHelpers: 'bundled',
|
39 | presets: ['@babel/preset-env']
|
40 | })] : []),
|
41 | ...(config.plugins || []),
|
42 | ]
|
43 | });
|
44 |
|
45 | const configs = [
|
46 | build({minified: false}),
|
47 | ];
|
48 |
|
49 | if (minifiedVersion) {
|
50 | configs.push(build({minified: true}))
|
51 | }
|
52 |
|
53 | return configs;
|
54 | };
|
55 |
|
56 | export default async () => {
|
57 | const year = new Date().getFullYear();
|
58 | const banner = `// Axios v${lib.version} Copyright (c) ${year} ${lib.author} and contributors`;
|
59 |
|
60 | return [
|
61 |
|
62 | ...buildConfig({
|
63 | input: namedInput,
|
64 | output: {
|
65 | file: `dist/esm/${outputFileName}.js`,
|
66 | format: "esm",
|
67 | preferConst: true,
|
68 | exports: "named",
|
69 | banner
|
70 | }
|
71 | }),
|
72 |
|
73 |
|
74 | ...buildConfig({
|
75 | input: defaultInput,
|
76 | es5: true,
|
77 | output: {
|
78 | file: `dist/${outputFileName}.js`,
|
79 | name,
|
80 | format: "umd",
|
81 | exports: "default",
|
82 | banner
|
83 | }
|
84 | }),
|
85 |
|
86 |
|
87 | ...buildConfig({
|
88 | input: defaultInput,
|
89 | es5: false,
|
90 | minifiedVersion: false,
|
91 | output: {
|
92 | file: `dist/browser/${name}.cjs`,
|
93 | name,
|
94 | format: "cjs",
|
95 | exports: "default",
|
96 | banner
|
97 | }
|
98 | }),
|
99 |
|
100 |
|
101 | {
|
102 | input: defaultInput,
|
103 | output: {
|
104 | file: `dist/node/${name}.cjs`,
|
105 | format: "cjs",
|
106 | preferConst: true,
|
107 | exports: "default",
|
108 | banner
|
109 | },
|
110 | plugins: [
|
111 | autoExternal(),
|
112 | resolve(),
|
113 | commonjs()
|
114 | ]
|
115 | }
|
116 | ]
|
117 | };
|