@automattic/webpack-inline-constant-exports-plugin

中文文档
1.0.1发布于 2026/10/20GPL-2.0-or-later零依赖近 30 天下载 2632

Webpack plugin to inline constant exports from modules

此软件包已被标记为弃用

No longer maintained. 1.0.1 supports webpack 5 including 5.112.

原始使用文档

webpack-inline-constant-exports-plugin

Detects that bindings exported from a module are constants and inlines them at the usage site.

constants.js

export const BLOGGER = 'BLOGGER_PLAN'; // strings
export const PREMIUM = 'PREMIUM_PLAN';
export const MONTHS_IN_YEAR = 12; // numbers
export const MONTLY_BILLING = false; // boolean
export const NO_PLAN = null; // null

app.js

import { BLOGGER, PREMIUM } from './constants';

console.log( BLOGGER, PREMIUM );

If the constants.js file is marked as constants module, eligible constants (strings, numbers, booleans, anything that's ===-equal to each other even for different instances) will be inlined into the importing module and the actual import will be removed:

bundled-app.js

console.log( 'BLOGGER_PLAN', 'PREMIUM_PLAN' );

Usage

webpack.config.js

const InlineConstantExportsPlugin = require( '@automattic/webpack-inline-constant-exports-plugin' );

module.exports = {
    plugins: [ new InlineConstantExportsPlugin( [ /\/constants.js/ ] ) ],
};

The constructor argument is an array of regexp matchers: if a matcher matches a module resource path, the module will be treated as an constant-exporting one and these exports will be inlined.

Side Effects

If you import bindings from a constants module:

import { BLOGGER, PREMIUM } from './constants';

it is assumed that the module is imported only to get the constant bindings, and not for its side effects. The import will be removed if all the imported bindings were inlined and the potential side effects will not be performed.

In other words, it's like the module declared sideEffects: false in its package.json.

版本与发布记录

@automattic/webpack-inline-constant-exports-plugin 共发布 3 个版本,首次发布于 2019/06/03;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.0.1latest2026/10/2018 天前
1.0.02020/12/115 年前
0.0.12019/06/037 年前

关于 @automattic/webpack-inline-constant-exports-plugin 的常见问题

@automattic/webpack-inline-constant-exports-plugin 是什么?

Webpack plugin to inline constant exports from modules注意:该包已被作者标记为弃用——No longer maintained. 1.0.1 supports webpack 5 including 5.112.

如何安装 @automattic/webpack-inline-constant-exports-plugin?

在项目目录运行 npm install @automattic/webpack-inline-constant-exports-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:webpack(^5.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@automattic/webpack-inline-constant-exports-plugin 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/automattic__webpack-inline-constant-exports-plugin 是否存在。

@automattic/webpack-inline-constant-exports-plugin 可以商用吗?

@automattic/webpack-inline-constant-exports-plugin 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@automattic/webpack-inline-constant-exports-plugin 的下载量有多少?

根据 npm 官方下载统计,@automattic/webpack-inline-constant-exports-plugin 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,632 次,日均约 88 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@automattic/webpack-inline-constant-exports-plugin 还在维护吗?

最新版本 1.0.1 发布于 2026/10/20(18 天前);至今共发布 3 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/06/03。作者已将其标记为弃用,新项目建议寻找替代方案。