2

我一直在使用 Webpack 的 DefinePlugin.runtimeValue 将计算的设置注入我的应用程序。

webpack.config.js

new webpack.DefinePlugin({
    COMPUTED_CONSTANT: webpack.DefinePlugin.runtimeValue(
        function () { return JSON.stringify(countPuppies()) }, []
    )
})
应用程序.js

const total = COMPUTED_CONSTANT

然而,我真正想做的是处理带有参数的函数。IE:

应用程序.js

var someValue = 7;

var total = COMPILE_TIME_GLOBAL_FUNC(someValue) // = 14
// Compiles to: var total = 14

有没有办法在 webpack 中完成这个或类似的事情(在编译时)?

4

0 回答 0