Skip to content

Commit

Permalink
add an esbuild bundler to the webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
stasguma committed May 26, 2024
1 parent b2fd4bf commit a39d3b9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
9 changes: 7 additions & 2 deletions config/build/buildWebpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type webpack from 'webpack';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import { EsbuildPlugin } from 'esbuild-loader';

import { devServer } from './devServer';
import { loaders } from './loaders';
Expand Down Expand Up @@ -31,7 +31,12 @@ export const buildWebpackConfig = function (
plugins: plugins(options),
optimization: {
runtimeChunk: 'single',
minimizer: [new CssMinimizerPlugin()],
minimizer: [
new EsbuildPlugin({
target: 'es2015',
css: true,
}),
],
},
};
};
32 changes: 8 additions & 24 deletions config/build/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,14 @@ export const loaders = function (

const svgLoader = initSvgLoader();

const babelLoader = {
test: /\.(js|ts)(x)?$/,
const esbuildLoader = {
// Match `.js`, `.jsx`, `.ts` or `.tsx` files
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
],
};
const typescriptLoader = {
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
loader: 'esbuild-loader',
options: {
target: 'es2015',
},
};

const cssLoader = initCssLoader({ isDev });
Expand All @@ -58,8 +43,7 @@ export const loaders = function (
fontLoader,
imageLoader,
svgLoader,
babelLoader,
typescriptLoader,
esbuildLoader,
cssLoader,
];
};
9 changes: 6 additions & 3 deletions config/build/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CopyPlugin from 'copy-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import Dotenv from 'dotenv-webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { EsbuildPlugin } from 'esbuild-loader';

import { type IBuildOptions } from './types/config';

Expand All @@ -21,9 +22,11 @@ export const plugins = function (
filename: isDev ? 'css/[name].css' : 'css/[name].[contenthash:8].css',
chunkFilename: isDev ? 'css/[id].css' : 'css/[id].[contenthash:8].css',
}),
new webpack.DefinePlugin({
__IS_DEV__: JSON.stringify(isDev),
// 'process.env': JSON.stringify(process.env),
new EsbuildPlugin({
define: {
__IS_DEV__: JSON.stringify(isDev),
// 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
}),
new Dotenv(),
];
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"lib": ["DOM", "ES2022", "DOM.Iterable"],
"strictNullChecks": true,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type webpack from 'webpack';
import type { IBuildEnvironment, IBuildPaths, TBuildMode } from './config/build/types/config';
import path from 'path';

import path from 'path';
import { buildWebpackConfig } from './config/build/buildWebpackConfig';

export default (env: IBuildEnvironment): webpack.Configuration => {
Expand Down

0 comments on commit a39d3b9

Please sign in to comment.