3

After building my angular4 application, webpack changed my image name from bg_node_new.png to bg_node_new.3746bc3ac9b1bf77d2aff2c2df901a48.png.

my webpack.config code is:

(function(module) {

    const path = require('path');
    const npm_cmd = process.env.npm_lifecycle_event;
    const p = !(require('yargs').argv.p || false);
    let config;

    module.exports = function(env) {

        let cmds = npm_cmd.split(":");
        const cmd = cmds.length >= 2 ? cmds[1] : null;
        const mod = cmds.length >= 3 ? cmds[2] : null;
        const aot = cmds.length >= 4 ? cmds[3] : null;

        const options = {
            p:!p,
            mod:mod,
            aot:aot,
            env:env,
            ngv:2,
            ctx:path.resolve(__dirname, "../../../../..")
        }
        //console.log(options);

        switch (cmd) {
          case 'app': 
            console.log("Building app");
            config = require('./wp.app')(options);
            break;
          case 'lib': 
            console.log("Building lib");
            config = require('./wp.lib')(options);
            break;
          case 'mod':
            console.log("Building mod");
            config = require('./wp.mod')(options);
            break
          default:
            console.log("Building app");
            config = require('./wp.app')(options);
            break;
        }

        return config;
    }

})(module);

Due to this, the image is not rendering in my app. how to resolve this issue?

Thanks in Advance!

Saravana
  • 524
  • 1
  • 6
  • 28

4 Answers4

8

UPDATED After OP's comment:

In your wp.base.js, remove [hash] from the following:

const raw_file_loader = {
    test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf)$/,
    use: 'file-loader?name=assets/[name].[ext]'
}

ORIGINAL Answer:

If you share your webpack config, I'll be ablr to answer better. However, Find a config like this in your webpack.config,

{
  test: /.*\.(gif|png|jpe?g|svg)$/i,
  use: [
    {
      loader: 'file-loader',
      options: {
        name: '/images/[name]_[hash:7].[ext]',
      }
    },
  ]
}

... and remove the [hash] part. Just keep it like this:

name: '/images/[name].[ext]',

FAISAL
  • 33,618
  • 10
  • 97
  • 105
0

This is because of hashing Angular does at the time of build to stop that use , provided you are using Angular CLI

 ng build --prod --output-hashing none
Rahul Singh
  • 19,030
  • 11
  • 64
  • 86
0

To solve the problem in React project, I set webpack.config.js like this

module: {
    rules: [
        {
            test: /\.(png|svg|jpg|gif)$/,
            loader: "file-loader",
            options: {
                name: 'images/[name].[ext]',
            },
        }
    ]
},
Michael Klishevich
  • 1,774
  • 1
  • 17
  • 17
0

you may also need to turn off source handling in your html loader

            {
            test: /\.html$/i,
            use: [
                {
                    loader: 'html-loader',
                    options: { minimize: false, sources: false }
                }
            ]
        }
William
  • 491
  • 5
  • 9