inject env var in webpack

This commit is contained in:
fyears 2021-12-01 10:10:39 +08:00
parent 2930fe5350
commit ccd3b49b4b

View File

@ -1,7 +1,10 @@
require("dotenv").config();
const path = require("path"); const path = require("path");
const webpack = require("webpack"); const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin");
const DEFAULT_DROPBOX_APP_KEY = process.env.DROPBOX_APP_KEY || "";
module.exports = { module.exports = {
entry: "./src/main.ts", entry: "./src/main.ts",
target: "web", target: "web",
@ -11,6 +14,9 @@ module.exports = {
libraryTarget: "commonjs", libraryTarget: "commonjs",
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({
"process.env.DEFAULT_DROPBOX_APP_KEY": `"${DEFAULT_DROPBOX_APP_KEY}"`,
}),
// Work around for Buffer is undefined: // Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10 // https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({