Webpack.mix,vue.js

编程入门 行业动态 更新时间:2024-10-26 10:27:40
Webpack.mix,vue.js - 编译参数(Webpack.mix, vue.js - compilation parameters)

我有一个webpack.mix.js文件(laravel mix),我用它来编译javascript和scss。 它运作良好,但我需要一个动态参数。 现在我有:

//let result = 'https://www.web1.com/'; let result = 'https://stage.web1.com/'; output: { publicPath: result, chunkFilename: 'js/[name].js' },

这工作正常,但我不得不在当地主机/舞台/现场版本之间切换时手动更改参数。

我想要做的是运行:

npm run local npm run stage npm run live

并且路径参数将被自动插入。

现在,npm运行prod执行此操作:

cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

我怎样才能在最后一行插入一个参数?

I have a webpack.mix.js file (laravel mix) that I use for compiling javascript and scss. It works well, but I need a dynamic parameter. Right now I have:

//let result = 'https://www.web1.com/'; let result = 'https://stage.web1.com/'; output: { publicPath: result, chunkFilename: 'js/[name].js' },

This works fine, but I have to change the parameter manually when I switch between the localhost/stage/live version.

What I would like to do is to run:

npm run local npm run stage npm run live

and the path parameter would be inserted automatically.

Right now, the npm run prod executes this:

cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

How can I insert a parameter into this last line?

最满意答案

要展开@ Ohgodwhy的评论:

let result = process.env.NODE_ENV == "production" ? 'https://www.web1.com/' : 'https://stage.web1.com/'

To expand on @Ohgodwhy's comment:

let result = process.env.NODE_ENV == "production" ? 'https://www.web1.com/' : 'https://stage.web1.com/'

更多推荐

本文发布于:2023-08-05 20:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mix   Webpack   js   vue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!