我尝试将.env
文件添加到目录的根目录,并尝试使用
[@bs.val] external graphqlUrl : string = "process.env.GRAPHQL_URL";
但是当我Js.log(graphqlUrl);
的时候undefined
!
.env
文件:
GRAPHQL_URL=https://api.example.com
我该如何访问?
谢谢!
我遵循Rem Lampa先生的建议,并在项目中安装了dotenv-webpack。然后,我按照dotenv-webpack
文档上的说明进行操作。
该webpack.config.js
文件现在如下所示:
const path = require('path');
const outputDir = path.join(__dirname, "build/");
const isProd = process.env.NODE_ENV === 'production';
const Dotenv = require('dotenv-webpack');
module.exports = {
entry: './src/Index.bs.js',
mode: isProd ? 'production' : 'development',
output: {
path: outputDir,
publicPath: outputDir,
filename: 'Index.js',
},
plugins: [
new Dotenv()
]
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句