• Empleos
  • Sobre nosotros
  • Empleos
    • Inicio
    • Empleos
    • Cursos y retos
  • Empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

128
Vistas
Modify webpack config from cli in npm run

I'm developing an react.js application, where I provide the index.html file in the public directory, but use webpack to replace placeholders (<%= placeholder %>) in it. Currently, the target strings are provided by options.json, which looks like:

{
  "placeholder": "value"
}

I can make it work rudimentarily with the following entry in package.json and the following relevant parts of the webpack.config.js

"scripts": {
  "build": "webpack --config=webpack.config.js --env env=production"
}

and

var options = require('./options.json')
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  [...]
  plugins: [
    new HtmlWebpackPlugin({
      template: "public/index.html",
      templateParameters: options
    })
  ]
}

My goal would be to run npm run build <user_provided_options.json> so that I can switch between different versions of values for the placeholders. How can I achieve that?

over 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda