Skip to content

Commit

Permalink
Use esbuild instead of webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
arashm committed May 27, 2024
1 parent e8a9ad7 commit 6533ed5
Show file tree
Hide file tree
Showing 9 changed files with 964 additions and 1,764 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["add-module-exports"]
}
2 changes: 0 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"plugins": [
"babel",
"jest"
],
"env": {
Expand Down
33 changes: 33 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const esbuild = require('esbuild');
const path = require('path');

// Common configuration
const commonConfig = {
entryPoints: [path.join(__dirname, '/src/jdate.js')],
bundle: true,
sourcemap: 'inline',
outfile: path.join(__dirname, '/lib/jdate.js'),
target: ['es2015'],
format: 'esm',
globalName: 'JDate'
};

// Development configuration
const devConfig = {
...commonConfig,
minify: false
};

// Production configuration
const prodConfig = {
...commonConfig,
minify: true,
outfile: path.join(__dirname, '/lib/jdate.min.js')
};

// Determine the mode
const mode = process.env.NODE_ENV || 'development';
const config = mode === 'development' ? devConfig : prodConfig;

// Build
esbuild.build(config).catch(() => process.exit(1));
34 changes: 14 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "1.1.5",
"description": "A Jalali to Gregorian converter with support of formatting output",
"scripts": {
"start": "webpack --progress --colors --watch --env dev",
"lint": "eslint ./src --ext .js --cache",
"test": "jest",
"watch": "webpack --watch --config webpack.dev.js",
"build": "webpack --config webpack.pro.js && webpack --config webpack.dev.js"
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
"start": "webpack --progress --colors --watch --env dev",
"watch": "node esbuild.dev.js",
"build": "NODE_ENV=production node esbuild.js && NODE_ENV=development node esbuild.js"
},
"repository": {
"type": "git",
Expand All @@ -29,23 +29,17 @@
},
"homepage": "https://github.com/arashm/JDate",
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-eslint": "^10.0.2",
"babel-jest": "^27.2.0",
"babel-loader": "^8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"eslint": "^7.5.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-babel": "^5.3.0",
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"babel-jest": "^29.7.0",
"esbuild": "^0.21.4",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jest": "^24.0",
"jest": "^27.2.0",
"jest-cli": "^27.2.0",
"jest-date-mock": "^1.0.7",
"webpack": "^5.53.0",
"webpack-cli": "^4.8.0",
"webpack-merge": "^5.0.0"
"eslint-plugin-jest": "^28.5.0",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"jest-date-mock": "^1.0.7"
},
"jest": {
"setupFiles": [
Expand Down
8 changes: 2 additions & 6 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export function replaceYear(str, date) {
return value;
}
case 'YY': {
const value = replaceYear(
str.replace(match, String(date.getFullYear()).slice(2)), date
);
const value = replaceYear(str.replace(match, String(date.getFullYear()).slice(2)), date);
return value;
}
default: {
Expand All @@ -67,9 +65,7 @@ export function replaceMonth(str, date) {
}
case 'MMM':
case 'MMMM': {
const value = replaceMonth(
str.replace(match, MONTH_NAMES[date.getMonth() - 1]), date
);
const value = replaceMonth(str.replace(match, MONTH_NAMES[date.getMonth() - 1]), date);
return value;
}
default: {
Expand Down
31 changes: 0 additions & 31 deletions webpack.common.js

This file was deleted.

7 changes: 0 additions & 7 deletions webpack.dev.js

This file was deleted.

9 changes: 0 additions & 9 deletions webpack.pro.js

This file was deleted.

Loading

0 comments on commit 6533ed5

Please sign in to comment.