Skip to content

import.meta with esbuild-loader #12

@JiangWeixian

Description

@JiangWeixian

import.meta not support in esbuild-loader(target: es2017) evanw/esbuild#349

I hack this issue by moving import.meta.webpackContext to js files, like

// utils/webpack-env
// refs: https://webpack.js.org/api/module-variables/#importmetawebpackcontext
export const contextRequire = import.meta.webpackContext('..', {
  recursive: true,
  regExp: /.tsx/,
  mode: 'sync',
})

then use it in App.tsx

import { contextRequire } from '@/utils/webpack-env'

console.log(contextRequire('./pages/index.tsx'))

or try supports options recommended in evanw/esbuild#349 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions