Nuxt/packages/webpack/src/presets/esbuild.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import { EsbuildPlugin } from 'esbuild-loader'
import type { WebpackConfigContext } from '../utils/config'
2020-09-02 12:27:27 +00:00
export function esbuild (ctx: WebpackConfigContext) {
// https://esbuild.github.io/getting-started/#bundling-for-the-browser
// https://gs.statcounter.com/browser-version-market-share
// https://nodejs.org/en/
const target = ctx.isServer ? 'es2020' : 'chrome85'
// https://github.com/nuxt/nuxt/issues/13052
ctx.config.optimization!.minimizer!.push(new EsbuildPlugin())
2020-09-02 12:27:27 +00:00
ctx.config.module!.rules!.push(
2020-09-02 12:27:27 +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
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))
},
resolve: {
fullySpecified: false
},
2020-09-02 12:27:27 +00:00
options: {
target,
...ctx.nuxt.options.webpack.loaders.esbuild,
loader: 'ts'
2020-09-02 12:27:27 +00:00
}
},
{
test: /\.m?[jt]sx$/,
2020-09-02 12:27:27 +00:00
loader: 'esbuild-loader',
options: {
target,
...ctx.nuxt.options.webpack.loaders.esbuild,
loader: 'tsx'
2020-09-02 12:27:27 +00:00
}
}
)
}