Skip to content

Commit 604f99d

Browse files
committed
chore: create dist bundles with rollup
1 parent 3f57aa7 commit 604f99d

File tree

5 files changed

+106
-58
lines changed

5 files changed

+106
-58
lines changed

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
],
1313

1414
"env": {
15+
"rollup": {
16+
"presets": [
17+
[
18+
"@babel/preset-env", {
19+
"modules": "false"
20+
}
21+
]
22+
]
23+
},
24+
1525
"es": {
1626
"presets": [
1727
[

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "rollup-plugin-esformatter",
33
"version": "0.7.0",
44
"description": "Rollup plugin to beautify bundle with esformatter",
5-
"main": "dist/cjs/index.js",
6-
"module": "dist/es/index.js",
5+
"main": "dist/index.js",
6+
"module": "dist/mjs/index.mjs",
77
"exports": {
88
".": {
9-
"require": "./dist/cjs/index.js",
10-
"import": "./dist/es/index.js",
9+
"require": "./dist/cjs/index.cjs",
10+
"import": "./dist/mjs/index.mjs",
1111
"default": "./dist/index.js"
1212
},
1313
"./dist/": "./dist/"
@@ -56,19 +56,19 @@
5656
"eslint-config-google": "0.14.0",
5757
"fancy-log": "1.3.3",
5858
"gulp": "4.0.2",
59-
"gulp-babel": "8.0.0",
6059
"gulp-bump": "3.1.3",
6160
"gulp-conventional-changelog": "2.0.29",
6261
"gulp-eslint": "6.0.0",
6362
"gulp-git": "2.10.0",
64-
"gulp-header-comment": "0.6.1",
6563
"gulp-jasmine": "4.0.0",
66-
"gulp-prettier": "2.3.0",
67-
"gulp-strip-banner": "0.0.2",
6864
"jasmine-core": "3.5.0",
6965
"q": "1.5.1",
7066
"rimraf": "3.0.2",
7167
"rollup": "1.32.0",
68+
"rollup-plugin-babel": "4.4.0",
69+
"rollup-plugin-license": "0.13.0",
70+
"rollup-plugin-prettier": "0.6.0",
71+
"rollup-plugin-strip-banner": "1.0.0",
7272
"run-sequence": "2.2.1",
7373
"tmp": "0.1.0"
7474
}

scripts/build/index.js

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,13 @@
2222
* SOFTWARE.
2323
*/
2424

25-
const path = require('path');
26-
const gulp = require('gulp');
27-
const babel = require('gulp-babel');
28-
const stripBanner = require('gulp-strip-banner');
29-
const headerComment = require('gulp-header-comment');
30-
const prettier = require('gulp-prettier');
31-
const config = require('../config');
25+
const rollup = require('rollup');
26+
const config = require('./rollup.config');
3227

33-
module.exports = gulp.series(
34-
buildCjs,
35-
buildEsm
36-
);
37-
38-
/**
39-
* Build CommonJS bundles.
40-
*
41-
* @return {NodeJS.WritableStream} The gulp stream.
42-
*/
43-
function buildCjs() {
44-
return build('cjs');
45-
}
46-
47-
/**
48-
* Build ESM bundles.
49-
*
50-
* @return {NodeJS.WritableStream} The gulp stream.
51-
*/
52-
function buildEsm() {
53-
return build('es');
54-
}
55-
56-
/**
57-
* Build bundle for given environment.
58-
*
59-
* @param {string} envName Environment id.
60-
* @return {NodeJS.WritableStream} The gulp stream.
61-
*/
62-
function build(envName) {
63-
return gulp.src(path.join(config.src, '**', '*.js'))
64-
.pipe(stripBanner())
65-
.pipe(babel({envName}))
66-
.pipe(headerComment({file: path.join(config.root, 'LICENSE')}))
67-
.pipe(prettier())
68-
.pipe(gulp.dest(path.join(config.dist, envName)));
69-
}
28+
module.exports = function build() {
29+
return rollup.rollup(config).then((bundle) => (
30+
Promise.all(config.output.map((output) => (
31+
bundle.write(output)
32+
)))
33+
));
34+
};

scripts/build/rollup.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2020 Mickael Jeanroy
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
const path = require('path');
26+
const stripBanner = require('rollup-plugin-strip-banner');
27+
const babel = require('rollup-plugin-babel');
28+
const license = require('rollup-plugin-license');
29+
const prettier = require('rollup-plugin-prettier');
30+
const config = require('../config');
31+
const pkg = require('../../package.json');
32+
33+
module.exports = {
34+
input: path.join(config.src, 'index.js'),
35+
output: [
36+
{
37+
format: 'cjs',
38+
file: path.join(config.dist, 'index.js'),
39+
},
40+
41+
{
42+
format: 'cjs',
43+
file: path.join(config.dist, 'cjs', 'index.cjs'),
44+
},
45+
46+
{
47+
format: 'es',
48+
file: path.join(config.dist, 'mjs', 'index.mjs'),
49+
},
50+
],
51+
52+
plugins: [
53+
stripBanner(),
54+
55+
babel({
56+
envName: 'rollup',
57+
}),
58+
59+
license({
60+
banner: {
61+
content: {
62+
file: path.join(config.root, 'LICENSE'),
63+
},
64+
},
65+
}),
66+
67+
prettier({
68+
parser: 'babel',
69+
}),
70+
],
71+
72+
external: [
73+
...Object.keys(pkg.dependencies),
74+
...Object.keys(pkg.peerDependencies),
75+
...Object.keys(pkg.devDependencies),
76+
],
77+
};

src/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import {rollupPluginStable} from './index-rollup-stable';
2929
const VERSION = rollup.VERSION || '0';
3030
const MAJOR_VERSION = Number(VERSION.split('.')[0]) || 0;
3131
const IS_ROLLUP_LEGACY = MAJOR_VERSION === 0;
32-
const esformatter = IS_ROLLUP_LEGACY ? rollupPluginLegacy : rollupPluginStable;
32+
const rollupEsformatter = IS_ROLLUP_LEGACY ? rollupPluginLegacy : rollupPluginStable;
3333

34-
export {
35-
esformatter,
36-
};
37-
38-
export default esformatter;
34+
export default rollupEsformatter;

0 commit comments

Comments
 (0)