UNPKG

2.03 kBJavaScriptView Raw
1import resolve from '@rollup/plugin-node-resolve';
2import commonjs from '@rollup/plugin-commonjs';
3import {terser} from "rollup-plugin-terser";
4import json from '@rollup/plugin-json';
5import { babel } from '@rollup/plugin-babel';
6import autoExternal from 'rollup-plugin-auto-external';
7import bundleSize from 'rollup-plugin-bundle-size'
8
9const lib = require("./package.json");
10const outputFileName = 'axios';
11const name = "axios";
12const input = './lib/axios.js';
13
14const 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
48export 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: "default",
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 // Node.js commonjs build
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};