Skip to content

Commit

Permalink
feat(bundler): Migrate babel -> esbuild
Browse files Browse the repository at this point in the history
- Migrate transpiler: babel -> esbuild
- Update related plugins: css-minimizer-webpack-plugin, terser-webpack-plugin -> esbuild built-in

Fix #3601
  • Loading branch information
netil committed Mar 18, 2024
1 parent f8758aa commit ff0a98c
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 1,856 deletions.
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -170,16 +170,12 @@ If you want to use 'billboard.js' without installation, load files directly from

## Supported Browsers

> - Basically will work on all SVG supported browsers.
> - Basically will work on all SVG and ES6+ supported browsers.
> - <sup>*</sup>Notes for legacy browsers:
> - Recommended to use `packaged` build or construct your own build following [`How to bundle for legacy browsers?`](https://github.com/naver/billboard.js/wiki/How-to-bundle-for-legacy-browsers%3F) instruction.
> - D3.js dropped the support of legacy browsers since [v6](https://observablehq.com/@d3/d3v6-migration-guide).
> - The support isn't fully guaranteed.
|Internet Explorer|Chrome|Firefox|Safari|iOS|Android|
|---|---|---|---|---|---|
|9+<sup>*</sup>|Latest|Latest|Latest|8+|4+|


## Dependency by version

Expand Down
50 changes: 0 additions & 50 deletions babel.config.cjs

This file was deleted.

4 changes: 0 additions & 4 deletions config/rollup/esm.js
@@ -1,5 +1,4 @@
import {readdirSync} from "fs";
import babel from '@rollup/plugin-babel';
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
Expand All @@ -26,9 +25,6 @@ const plugins = [
runOnce: true
}),
resolve(),
babel({
babelHelpers: "runtime"
}),
typescript(),
replace({
"__VERSION__": version,
Expand Down
18 changes: 0 additions & 18 deletions config/terserConfig.cjs

This file was deleted.

12 changes: 8 additions & 4 deletions config/webpack/packaged.cjs
@@ -1,9 +1,7 @@
const {merge} = require("webpack-merge");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const terserConfig = require("../terserConfig.cjs");
const banner = require("../template/banner.cjs");

const {EsbuildPlugin} = require("esbuild-loader");

const config = {
entry: {
Expand All @@ -13,7 +11,13 @@ const config = {
optimization: {
usedExports: true,
minimize: true,
minimizer: [new TerserPlugin(terserConfig)]
minimizer: [
new EsbuildPlugin({
include: /\.min\.js$/,
target: "es2015",
format: undefined
})
]
},
plugins: [
new webpack.BannerPlugin({
Expand Down
10 changes: 7 additions & 3 deletions config/webpack/plugin.cjs
Expand Up @@ -3,9 +3,8 @@ const webpack = require("webpack");
const fs = require("fs");
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const terserConfig = require("../terserConfig.cjs");
const banner = require("../template/banner.cjs");
const {EsbuildPlugin} = require("esbuild-loader");

const srcPath = "./src/Plugin/";
const distPath = path.resolve(__dirname, "../../dist/plugin/");
Expand Down Expand Up @@ -68,7 +67,12 @@ module.exports = (common, env) => {
config.optimization = {
usedExports: true,
minimize: true,
minimizer: [new TerserPlugin(terserConfig)]
minimizer: [
new EsbuildPlugin({
target: "es2015",
format: undefined
})
]
};
}

Expand Down
19 changes: 6 additions & 13 deletions config/webpack/production.cjs
Expand Up @@ -2,10 +2,8 @@ const {merge} = require("webpack-merge");
const webpack = require("webpack");
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const terserConfig = require("../terserConfig.cjs");
const banner = require("../template/banner.cjs");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const {EsbuildPlugin} = require("esbuild-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");

Expand All @@ -32,16 +30,11 @@ const config = {
usedExports: true,
minimize: true,
minimizer: [
new TerserPlugin(terserConfig),
new CssMinimizerPlugin({
test: /\.min\.css$/i,
minimizerOptions: {
preset: [
"default", {
discardComments: true
}
]
}
new EsbuildPlugin({
include: /\.min\.(js|css)$/,
target: "es2015",
css: true,
format: undefined
})
]
},
Expand Down
16 changes: 6 additions & 10 deletions config/webpack/theme.cjs
Expand Up @@ -5,7 +5,7 @@ const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const WebpackCleanPlugin = require("webpack-clean");
const banner = require("../template/banner.cjs");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const {EsbuildPlugin} = require("esbuild-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const srcPath = "./src/scss/theme/";
Expand Down Expand Up @@ -47,15 +47,11 @@ const config = {
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin({
test: /\.min\.css$/i,
minimizerOptions: {
preset: [
"default", {
discardComments: true
}
]
}
new EsbuildPlugin({
include: /\.min\.css$/,
target: "es2015",
css: true,
format: undefined
})
]
},
Expand Down
7 changes: 5 additions & 2 deletions karma.conf.cjs
Expand Up @@ -64,8 +64,11 @@ module.exports = function(config) {
}
},
{
test: /(\.[jt]s)$/,
loader: "babel-loader",
test: /\.[jt]s$/,
loader: "esbuild-loader",
options: {
target: "es2015"
},
exclude: {
and: [/node_modules/],
not: [/(d3\-.*)$/, /internmap/]
Expand Down
31 changes: 5 additions & 26 deletions package.json
Expand Up @@ -101,17 +101,8 @@
"d3-zoom": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@babel/eslint-parser": "^7.23.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.24.0",
"@commitlint/cli": "19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@rollup/plugin-babel": "^6.0.4",
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^11.1.6",
Expand All @@ -125,19 +116,8 @@
"@types/d3": "^7.4.3",
"@types/mocha": "^10.0.6",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"babel-helper-modules": "^6.0.0",
"babel-loader": "^9.1.3",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-minify-constant-folding": "^0.5.0",
"babel-plugin-minify-dead-code-elimination": "^0.5.2",
"babel-plugin-minify-guarded-expressions": "^0.4.4",
"babel-plugin-minify-numeric-literals": "^0.4.3",
"babel-plugin-minify-type-constructors": "^0.4.3",
"babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
"babel-plugin-transform-merge-sibling-variables": "^6.9.5",
"babel-plugin-transform-minify-booleans": "^6.9.4",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"better-docs": "^2.7.3",
"chai": "^4.3.10",
"clean-webpack-plugin": "^4.0.0",
Expand All @@ -146,12 +126,12 @@
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"css-loader": "^6.10.0",
"css-minimizer-webpack-plugin": "^6.0.0",
"d3-color": "^3.1.0",
"d3-delaunay": "^6.0.4",
"d3-format": "^3.1.0",
"d3-polygon": "^3.0.1",
"docdash": "^2.0.2",
"esbuild-loader": "^4.0.3",
"eslint": "^8.57.0",
"eslint-config-naver": "^2.1.0",
"eslint-plugin-import": "^2.29.1",
Expand Down Expand Up @@ -188,7 +168,6 @@
"string-replace-loader": "^3.1.0",
"style-loader": "^3.3.4",
"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.10",
"tslib": "^2.6.2",
"typescript": "5.4.2",
"webpack": "^5.90.3",
Expand Down
2 changes: 1 addition & 1 deletion test/api/chart-spec.ts
Expand Up @@ -111,7 +111,7 @@ describe("API chart", () => {
// all methods should be ressetted
Object.keys(chart).forEach(key => {
expect(chart[key]()).to.be.undefined;
expect(/^function()/.test(chart[key].toString())).to.be.true;
expect(/^\(\)\s?=\>\s?\{/.test(chart[key].toString())).to.be.true;
});

expect(bb.instance.indexOf(chart) === -1).to.be.true;
Expand Down
4 changes: 4 additions & 0 deletions test/interactions/subchart-spec.ts
Expand Up @@ -581,6 +581,8 @@ describe("SUBCHART", () => {
expect(
this.internal.$el.subchart.main.selectAll(`.${$LINE.line}-data1`).size()
).to.be.equal(1);

done();
}
});
});
Expand All @@ -602,6 +604,8 @@ describe("SUBCHART", () => {
expect(
main.selectAll(`.${$LINE.line}-data2`).size()
).to.be.equal(1);

done();
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/shape/arc-spec.ts
Expand Up @@ -717,15 +717,15 @@ describe("SHAPE ARC", () => {
checkExpand(done);
});

it("set options: data.type='donut'", done => {
it("set options: data.type='donut'", () => {
args.data.type = "donut";
});

it("check Donut's expand", done => {
checkExpand(done);
});

it("set options: data.type='gauge'", done => {
it("set options: data.type='gauge'", () => {
args.data.type = "donut";
});

Expand Down
7 changes: 5 additions & 2 deletions webpack.config.cjs
Expand Up @@ -44,8 +44,11 @@ const config = {
module: {
rules: [
{
test: /(\.[jt]s)$/,
loader: "babel-loader",
test: /\.[jt]s$/,
loader: "esbuild-loader",
options: {
target: "es2015"
},
exclude: {
and: [/node_modules/],
not: [/(d3\-.*)$/, /internmap/]
Expand Down

0 comments on commit ff0a98c

Please sign in to comment.