Skip to content

Commit

Permalink
Replaced webpack with rollup; (#4596)
Browse files Browse the repository at this point in the history
Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
DigitalBrainJS and jasonsaayman committed May 3, 2022
1 parent a41f129 commit fe25630
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
22 changes: 7 additions & 15 deletions Gruntfile.js
Expand Up @@ -29,18 +29,6 @@ module.exports = function(grunt) {
all: {}
},

usebanner: {
all: {
options: {
banner: '<%= meta.banner %>',
linebreak: false
},
files: {
src: ['dist/*.js']
}
}
},

eslint: {
target: ['lib/**/*.js']
},
Expand Down Expand Up @@ -77,7 +65,11 @@ module.exports = function(grunt) {
}
},

webpack: require('./webpack.config.js')
shell: {
rollup: {
command: 'rollup -c -m'
}
}
});

grunt.registerMultiTask('package2bower', 'Sync package.json to bower.json', function() {
Expand All @@ -104,6 +96,6 @@ module.exports = function(grunt) {
});

grunt.registerTask('test', 'Run the jasmine and mocha tests', ['eslint', 'mochaTest', 'karma:single']);
grunt.registerTask('build', 'Run webpack and bundle the source', ['clean', 'webpack', 'usebanner']);
grunt.registerTask('version', 'Sync version info for a release', ['usebanner', 'package2bower', 'package2env']);
grunt.registerTask('build', 'Run rollup and bundle the source', ['clean', 'shell:rollup']);
grunt.registerTask('version', 'Sync version info for a release', ['package2bower', 'package2env']);
};
8 changes: 8 additions & 0 deletions package.json
Expand Up @@ -31,6 +31,11 @@
},
"homepage": "https://axios-http.com",
"devDependencies": {
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"abortcontroller-polyfill": "^1.7.3",
"coveralls": "^3.1.1",
"dtslint": "^4.2.1",
Expand All @@ -44,6 +49,7 @@
"grunt-eslint": "^24.0.0",
"grunt-karma": "^4.0.2",
"grunt-mocha-test": "^0.13.3",
"grunt-shell": "^3.0.1",
"grunt-webpack": "^5.0.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^2.4.1",
Expand All @@ -60,6 +66,8 @@
"load-grunt-tasks": "^5.1.0",
"minimist": "^1.2.6",
"mocha": "^8.2.1",
"rollup": "^2.67.0",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^4.5.0",
"terser-webpack-plugin": "^4.2.3",
"typescript": "^4.6.3",
Expand Down
60 changes: 60 additions & 0 deletions rollup.config.js
@@ -0,0 +1,60 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import {terser} from "rollup-plugin-terser";
import json from '@rollup/plugin-json';

const lib = require("./package.json");
const outputFileName = 'axios';
const name = "axios";
const input = './lib/axios.js';

const buildConfig = (config) => {

const build = ({minified}) => ({
input,
...config,
output: {
...config.output,
file: `${config.output.file}.${minified ? "min.js" : "js"}`
},
plugins: [
json(),
resolve({browser: true}),
commonjs(),
minified && terser(),
...(config.plugins || []),
]
});

return [
build({minified: false}),
build({minified: true}),
];
};

export default async () => {
const year = new Date().getFullYear();
const banner = `// ${lib.name} v${lib.version} Copyright (c) ${year} ${lib.author}`;

return [
...buildConfig({
output: {
file: `dist/${outputFileName}`,
name,
format: "umd",
exports: "default",
banner
}
}),

...buildConfig({
output: {
file: `dist/esm/${outputFileName}`,
format: "esm",
preferConst: true,
exports: "named",
banner
}
})
]
};

0 comments on commit fe25630

Please sign in to comment.