【问题标题】:Change configuration values post webpack build在 webpack 构建后更改配置值
【发布时间】:2017-12-13 14:14:58
【问题描述】:

在静态文件夹中我有 config.js

module.exports = {
  config: {
    urls: {
     auth: localhost
    }
  }
}

我运行npm run build 并将输出(dist 文件夹)发送到客户端以部署到他们的生产环境中。我希望客户端能够编辑 auth 的值。

config 当前配置为 webpack 中的外部文件:

const config = require(path.join(paths.STATIC, 'config.js'))

externals: [{
    appsetting: JSON.stringify(config)
}]

如何让 config.js 识别 webpack 构建后的更改?

【问题讨论】:

    标签: javascript webpack ecmascript-6 vuejs2


    【解决方案1】:

    这样的事情怎么样,使用axios

    function readConfig () {
       return axios.get('./static/config.js').then((response) => {
           return response.data
       });
    }
    
    readConfig().then((config) => {
        // Do stuff
    });
    

    并确保将 config.js 复制到 static/ 文件夹。

    【讨论】:

      【解决方案2】:

      在 webpack.config 中为 config.js 创建一个入口文件,并在您使用配置的其他文件中导入/要求 config.js

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-18
        • 1970-01-01
        • 1970-01-01
        • 2019-04-04
        • 1970-01-01
        • 2021-11-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多