Skip to content

Including images from the 'static' dir to a CLI generated Webpack project results in duplication in output bundle #968

Open
@chrisckc

Description

@chrisckc

I'm submitting a bug report
Here is another issue with the CLI generated webpack config that soon becomes apparent once an app starts to be built.

  • Loader/bundler:
    Webpack

Current behavior:
If you go down the logical steps needed to include an image in your app, ie. add an image inside 'static/images' dir then add the image to your html file like this:

 <img src="../static/images/test.png"

After running 'au build --env prod` and inspecting the contents of the 'dist' dir you will discover that the image has been included twice.

You will see it in it's correct form as a hashed filename such as "904ca927cf30ddc1d7dbbd6593f2f78e.png" as generated by the webpack url-loader plugin.

You will also see it at "images/test.png" as it is also copied over by the CopyWebpackPlugin which results in a second redundant copy.

The offending config entry is here:

...when(production || server, new CopyWebpackPlugin([
      { from: 'static', to: outDir }])),
  • What is the expected behavior?
    Expected that the image would not included in the output bundle twice.

To fix this issue, the config entry need to be changed to this:

// url-loader handles bundling of png/jpg/gif/svg etc.
// We only need to specify files here that are not referenced in the source files
...when(production || server, new CopyWebpackPlugin([
      { from: 'static/favicon.ico', to: 'favicon.ico' }])),

We only need to copy over the favicon as it is not referenced in the source so is not picked up by the webpack rules.

  • What is the motivation / use case for changing the behavior?
    To provide a better starting experience for new comers to Aurelia or Aurelia / webpack combination.

I am not new to Aurelia but new to webpack, and have so far had to spend quite some time sorting out issues with the webpack config to support various use cases. Simply following the path of using popular libraries such a jQuery or Bootstrap has proven to be problematic as i have detailed in another recent issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions