使用命令行参数运行 webpack [英] run webpack with command line args
问题描述
我一直在尝试将 args 从命令行传递到 webpack 插件.我可以通过 process.argv 访问 args 但在那之后 wwebpack 失败并出现错误:未找到输入模块中的错误:错误:无法解析模块似乎 webpack 将 args 视为它需要查找的文件夹.这就是我传递参数的方式:webpack accessKey=myKey
I've been trying to pass args from command line to webpack plugin. I can access the args via process.argv but after that wwebpack fails with error: ERROR in Entry module not found: Error: Cannot resolve module It seems that webpack treats the args as folders it needs to find. This is how I pass the args: webpack accessKey=myKey
已解决:
看到了两种方法:
在调用 webpack 之前添加参数并使用 process.env.访问它:例如:myparam=1231 webpack在 webpack 配置文件中:process.env.myparam == 1231
Add the param before calling webpack and use the process.env. to access it: For example : myparam=1231 webpack in the webpack config file: process.env.myparam == 1231
在 webpack 命令之后添加 args 作为使用 -- 的标志.例如: webpack --myparam在 webpack 配置文件中: process.argv[2] == --myparam
Add the args after the webpack command as flags using --. For example : webpack --myparam in the webpack config file: process.argv[2] == --myparam
希望这有帮助
推荐答案
尝试在 webpack 命令之前传递它们:
Try passing them before the webpack command:
accessKey=myKey webpack
这篇关于使用命令行参数运行 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!