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

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import esbuildLoader from 'esbuild-loader'
2020-09-02 12:27:27 +00:00
import { WebpackConfigContext } from '../utils/config'
export function esbuild (ctx: WebpackConfigContext) {
const { config } = ctx
// 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 ? 'es2019' : 'chrome85'
// https://github.com/nuxt/framework/issues/2372
config.optimization!.minimizer!.push(new (esbuildLoader as unknown as typeof import('esbuild-loader')).ESBuildMinifyPlugin())
2020-09-02 12:27:27 +00:00
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: {
loader: 'ts',
target
2020-09-02 12:27:27 +00:00
}
},
{
test: /\.m?[jt]sx$/,
2020-09-02 12:27:27 +00:00
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target
2020-09-02 12:27:27 +00:00
}
}
)
}