@syumai/esbuild-loader
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

esbuild-loader

  • A Webpack loader to run esbuild's build command on given path.
  • This loader is useful for embedding partial TypeScript codes into your another code as bundled string.

Installation

npm i -D @syumai/esbuild-loader

Usage

webpack.config.ts

import { BuildOptions } from "esbuild";

const config = {
  ...
  module: {
    rules: [
      {
        test: /\.ts$/,
        resourceQuery: /source/,
        type: "asset/source",
        use: [
          {
            loader: "@syumai/esbuild-loader",
            options: {
              build: {
                minify: false,
                platform: "neutral",
              } satisfies BuildOptions, // `build` key accepts esbuild's BuildOptions.
            },
          },
        ],
      },
  ...

Code

  • bar.ts
export const bar = "bar";
  • foo.ts
import { bar } from "./bar";
export const fooBar = "foo" + bar;
  • index.ts
import fooCode from "./foo?source";
/* result:
// src/bar.ts
var bar = "bar";

// src/foo.ts
var fooBar = "foo" + bar;
export {
  fooBar
};
*/

License

MIT

Author

syumai

Readme

Keywords

none

Package Sidebar

Install

npm i @syumai/esbuild-loader

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

3.9 kB

Total Files

6

Last publish

Collaborators

  • syumai