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 |
|
9 | const lib = require("./package.json");
|
10 | const outputFileName = 'axios';
|
11 | const name = "axios";
|
12 | const input = './lib/axios.js';
|
13 |
|
14 | const buildConfig = ({es5, browser = true, minifiedVersion = true, ...config}) => {
|
15 |
|
16 | const build = ({minified}) => ({
|
17 | input,
|
18 | ...config,
|
19 | output: {
|
20 | ...config.output,
|
21 | file: `${config.output.file}.${minified ? "min.js" : "js"}`
|
22 | },
|
23 | plugins: [
|
24 | json(),
|
25 | resolve({browser}),
|
26 | commonjs(),
|
27 | minified && terser(),
|
28 | minified && bundleSize(),
|
29 | ...(es5 ? [babel({
|
30 | babelHelpers: 'bundled',
|
31 | presets: ['@babel/preset-env']
|
32 | })] : []),
|
33 | ...(config.plugins || []),
|
34 | ]
|
35 | });
|
36 |
|
37 | const configs = [
|
38 | build({minified: false}),
|
39 | ];
|
40 |
|
41 | if (minifiedVersion) {
|
42 | configs.push(build({minified: true}))
|
43 | }
|
44 |
|
45 | return configs;
|
46 | };
|
47 |
|
48 | export default async () => {
|
49 | const year = new Date().getFullYear();
|
50 | const banner = `// Axios v${lib.version} Copyright (c) ${year} ${lib.author} and contributors`;
|
51 |
|
52 | return [
|
53 | ...buildConfig({
|
54 | es5: true,
|
55 | output: {
|
56 | file: `dist/${outputFileName}`,
|
57 | name,
|
58 | format: "umd",
|
59 | exports: "named",
|
60 | banner
|
61 | }
|
62 | }),
|
63 |
|
64 | ...buildConfig({
|
65 | output: {
|
66 | file: `dist/esm/${outputFileName}`,
|
67 | format: "esm",
|
68 | preferConst: true,
|
69 | exports: "named",
|
70 | banner
|
71 | }
|
72 | }),
|
73 |
|
74 | {
|
75 | input,
|
76 | output: {
|
77 | file: `dist/node/${name}.cjs`,
|
78 | format: "cjs",
|
79 | preferConst: true,
|
80 | exports: "default",
|
81 | banner
|
82 | },
|
83 | plugins: [
|
84 | autoExternal(),
|
85 | resolve(),
|
86 | commonjs()
|
87 | ]
|
88 | }
|
89 | ]
|
90 | };
|