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

Ref naver#3601
  • Loading branch information
netil committed Mar 4, 2024
1 parent d28258e commit 9426f87
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 1,663 deletions.
50 changes: 0 additions & 50 deletions babel.config.cjs

This file was deleted.

4 changes: 0 additions & 4 deletions config/rollup/esm.js
Original file line number Diff line number Diff line change
@@ -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.

11 changes: 7 additions & 4 deletions config/webpack/packaged.cjs
Original file line number Diff line number Diff line change
@@ -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,12 @@ const config = {
optimization: {
usedExports: true,
minimize: true,
minimizer: [new TerserPlugin(terserConfig)]
minimizer: [
new EsbuildPlugin({
include: /\.min\.js$/,
target: "es2015"
})
]
},
plugins: [
new webpack.BannerPlugin({
Expand Down
9 changes: 6 additions & 3 deletions config/webpack/plugin.cjs
Original file line number Diff line number Diff line change
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,11 @@ module.exports = (common, env) => {
config.optimization = {
usedExports: true,
minimize: true,
minimizer: [new TerserPlugin(terserConfig)]
minimizer: [
new EsbuildPlugin({
target: "es2015"
})
]
};
}

Expand Down
18 changes: 5 additions & 13 deletions config/webpack/production.cjs
Original file line number Diff line number Diff line change
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,10 @@ 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
})
]
},
Expand Down
15 changes: 5 additions & 10 deletions config/webpack/theme.cjs
Original file line number Diff line number Diff line change
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,10 @@ 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
})
]
},
Expand Down
7 changes: 5 additions & 2 deletions karma.conf.cjs
Original file line number Diff line number Diff line change
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
23 changes: 1 addition & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,8 @@
"d3-zoom": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@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.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.23.9",
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^11.1.6",
Expand All @@ -127,17 +118,6 @@
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.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",
"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.3.3",
"webpack": "^5.90.3",
Expand Down
2 changes: 1 addition & 1 deletion test/api/chart-spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 9426f87

Please sign in to comment.