zebp / const-module-loader

A Webpack loader for compile-time execution of ESM modules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

const-module-loader

A Webpack loader for compile-time execution of ESM modules.

downloads npm version MIT license

Installation

# NPM
$ npm install const-module-loader
# Yarn
$ yarn add const-module-loader
# PNPM
$ pnpm add const-module-loader
# Bun
$ bun add const-module-loader

Usage

Depending on what framework you are using your configuration will look slightly different. If you are using a Vite based framework you should instead look towards vite-plugin-const, which is the same functionality but for Vite based frameworks.

Webpack

Add const-module-loader as a module rules in your webpack.config.js.

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.const.ts/,
        use: [{ loader: "const-module-loader" }],
      },
    ],
  },
};

NextJS

Add const-module-loader as a module rules in the webpack section of your next.config.mjs.

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (
    config,
    { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
  ) => {
    config.module.rules.push({
      test: /\.const.ts/,
      use: [{ loader: "const-module-loader" }],
    });

    return config;
  },
};

License

Distributed under the MIT License. See LICENSE for more information.

About

A Webpack loader for compile-time execution of ESM modules.

License:MIT License


Languages

Language:TypeScript 100.0%