我有一个JavaScript AWS Lambda函数,我在部署前进行了WebPacking。我看到的问题是,我的应用程序中的所有process.env.VARNAME都被替换为静态值,而不是在运行时使用的Lambda环境变量的剩余变量。
根据我的研究,我认为这与DefinePlugin的默认行为有关,但我不确定如何禁用DefinePlugin。有人知道如何解决这个问题吗?
这是我的webpack.config.js:
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: {
entry: './src/lib/index.js',
},
target: 'node',
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
"fs": false,
"tls": false,
"net": false,
"dns": false,
"child_process": false,
"dtrace-provider": false
}
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
})
]
},
output: {
library: {
type: 'commonjs-static'
},
filename: "lib.js",
path: path.resolve(__dirname, 'build'),
chunkFormat: 'commonjs'
},
plugins: [
new NodePolyfillPlugin()
]
};
字符串
1条答案
按热度按时间7tofc5zh1#
我发现了这一点。下面是我的webpack.js.js。具体来说,webpack.DefinePlugin({ 'process. env':'process. env'})的插件条目是我需要避免的。
字符串