Skip to content

Include scripts with filenames containing hash using custom webpack config #12582

Closed
@mboughaba

Description

@mboughaba

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

angular/cli 6 supports custom webpack config were one can specify a custom application bootstrap.

"projects": {
  "custom-name": {
    // ...
    "architect": {
      // ...
      "build": {
        "builder": "@angular-devkit/build-webpack:webpack",
        "options": {
          "webpackConfig": "webpack.config.js"
        }
      }
    }

custom webpack config can be specified as such

 const path = require('path');
 const config = {
   entry: './src/custom-app.js',
   mode: 'production',
   output: {
     path: path.resolve(__dirname, 'dist'),
     filename: 'custom-app.js'
   }
 };
 module.exports = config;

then the output bundle can be reference in angular.json

"scripts": [
  { "input": "dist/custom-app.js", "lazy": true }
]

and then used as such

export class AppComponent {
  ngOnInit(): void {
    const customApp = new Worker('custom-app.js');
  }
}

Problem/Question/Request

Caching might become a problem with the setup above! What if we need to hash the custom-app.js bundle using webpack hashcontent?

 const path = require('path');
 const config = {
   entry: './src/custom-app.js',
   mode: 'production',
   output: {
     path: path.resolve(__dirname, 'dist'),
     filename: '[name][contenthash].js'
   }
 };
 module.exports = config;

This will no longer result in custom-app.js but instead something like custom-app1247989898989.js.

Is there a way to load the hashed file in angular?

I am sorry if this might looks as a support question, but I got no luck on SE https://stackoverflow.com/questions/52785348/angular-cli-reference-a-hashed-scripts

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