网络包装-内线-恒定-导出-插件
检测到从模块中导出的约束是常数,并在使用站点内嵌.
常数.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
应用程序.js
import { BLOGGER, PREMIUM } from './constants';
console.log( BLOGGER, PREMIUM );
如果 constants.js 文件被标记为常数模块,符合条件的常数(字符串,数字,
布尔斯,什么的 ===- 彼此平等,即使情况不同)
进入导入模块,并删除实际导入:
捆绑应用.js
console.log( 'BLOGGER_PLAN', 'PREMIUM_PLAN' );
使用量
网络包装. config.js
const InlineConstantExportsPlugin = require( '@automattic/webpack-inline-constant-exports-plugin' );
module.exports = {
plugins: [ new InlineConstantExportsPlugin( [ /\/constants.js/ ] ) ],
};
构建器参数是一个正则表达式匹配器的阵列: 如果匹配器匹配模块资源 路径,该模块将被视为一个不断输出的模块,这些出口将被内含.
边效果
如果从常数模块导入绑定值:
import { BLOGGER, PREMIUM } from './constants';
假定该模块的进口只是为了获得恒定装订,而不是为了其 副作用。 如果所有进口的装订物被内嵌,并且 潜在的副作用将不会发生.
换句话说,这就像模块宣布 sideEffects: false 联合国 package.json。 。 。 .