0

I have an angular 7 application, everything builds fine. I have a bunch of SASS files, they get complied and included at runtime. All is well.

I am trying to create some static html pages for developer documentation that use the same theme as the compiled one, problem is, in our test environment the css file that gets built/included is a cache-bust version like styles.ac795370d5a11a9e4dc3.css so i cant hard code a link to my static HTML pages.

Is there a way with angular.json during the build to create another "copy" of the generated css file and drop it in a folder of my choosing?

2
  • So, as far as another copy is concerned, it looks like it's not possible within the angular.json itself. A simple solution would be to make an npm script that runs the build, then use a postscript to copy the files without the hash. I'll add this as an answer. Commented Aug 5, 2019 at 2:28
  • You can try styles*.css? Commented Aug 5, 2019 at 2:28

1 Answer 1

3

As far as "another copy" is concerned, it looks like it's not possible within the angular.json itself.

A simple solution would be to make an npm script that runs the build, then use a postscript to copy the files without the hash.

Eg - package.json

{
  ...
  scripts: [
    "build:prod": "ng build --prod",
    "postbuild:prod": "cp dist/<your-proj-dir>/styles.*.css dist/<your-proj-dir>/styles.css"
  ],
  ...
}

In the cp command, you can copy it anywhere. I just assumed you would want it in the same directory.

Sign up to request clarification or add additional context in comments.

1 Comment

If your build machine is a different OS (linux) then you'll have problems. I like the postbuild. Here is what I used...I needed the raw style copied to the dist folder. used a package called shx to run powershell.... "build:prod": "ng build --prod --source-map", "postbuild:prod": "shx cp -f ./src/styles.scss ./dist/styles.scss",

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.