2023-02-08 12:09:30 +00:00
|
|
|
import { EsbuildPlugin } from 'esbuild-loader'
|
2022-12-11 21:44:52 +00:00
|
|
|
import type { WebpackConfigContext } from '../utils/config'
|
2020-09-02 12:27:27 +00:00
|
|
|
|
|
|
|
export function esbuild (ctx: WebpackConfigContext) {
|
2020-10-30 11:55:17 +00:00
|
|
|
// https://esbuild.github.io/getting-started/#bundling-for-the-browser
|
|
|
|
// https://gs.statcounter.com/browser-version-market-share
|
|
|
|
// https://nodejs.org/en/
|
2023-08-07 22:03:40 +00:00
|
|
|
const target = ctx.isServer ? 'es2020' : 'chrome85'
|
2020-10-30 11:55:17 +00:00
|
|
|
|
2023-01-19 19:37:07 +00:00
|
|
|
// https://github.com/nuxt/nuxt/issues/13052
|
2023-07-24 19:46:09 +00:00
|
|
|
ctx.config.optimization!.minimizer!.push(new EsbuildPlugin())
|
2020-09-02 12:27:27 +00:00
|
|
|
|
2023-07-24 19:46:09 +00:00
|
|
|
ctx.config.module!.rules!.push(
|
2020-09-02 12:27:27 +00:00
|
|
|
{
|
2021-10-14 13:21:55 +00:00
|
|
|
test: /\.m?[jt]s$/i,
|
2020-09-02 12:27:27 +00:00
|
|
|
loader: 'esbuild-loader',
|
|
|
|
exclude: (file) => {
|
|
|
|
// Not exclude files outside node_modules
|
2022-02-25 19:11:01 +00:00
|
|
|
file = file.split('node_modules', 2)[1]
|
|
|
|
if (!file) { return false }
|
2020-09-02 12:27:27 +00:00
|
|
|
|
|
|
|
return !ctx.transpile.some(module => module.test(file))
|
|
|
|
},
|
2021-04-21 15:10:53 +00:00
|
|
|
resolve: {
|
2024-04-05 18:08:32 +00:00
|
|
|
fullySpecified: false,
|
2021-04-21 15:10:53 +00:00
|
|
|
},
|
2020-09-02 12:27:27 +00:00
|
|
|
options: {
|
2023-06-07 12:50:12 +00:00
|
|
|
target,
|
|
|
|
...ctx.nuxt.options.webpack.loaders.esbuild,
|
2024-04-05 18:08:32 +00:00
|
|
|
loader: 'ts',
|
|
|
|
},
|
2020-09-02 12:27:27 +00:00
|
|
|
},
|
|
|
|
{
|
2021-10-14 13:21:55 +00:00
|
|
|
test: /\.m?[jt]sx$/,
|
2020-09-02 12:27:27 +00:00
|
|
|
loader: 'esbuild-loader',
|
|
|
|
options: {
|
2023-06-07 12:50:12 +00:00
|
|
|
target,
|
|
|
|
...ctx.nuxt.options.webpack.loaders.esbuild,
|
2024-04-05 18:08:32 +00:00
|
|
|
loader: 'tsx',
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 12:27:27 +00:00
|
|
|
)
|
|
|
|
}
|