简体   繁体   English

Angular CLI在scss构建上创建css文件“复制”

[英]Angular CLI create a css file “copy” on scss build

I have an angular 7 application, everything builds fine. 我有一个angular 7应用程序,一切正常。 I have a bunch of SASS files, they get complied and included at runtime. 我有一堆SASS文件,它们会在运行时被编译并包含在内。 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. 我正在尝试为开发人员文档创建一些静态html页面,这些页面使用与已编译主题相同的主题,问题是,在我们的测试环境中,已构建/包含的css文件是像styles.ac795370d5a11a9e4dc3.css这样的缓存styles.ac795370d5a11a9e4dc3.css版本我无法硬编码到静态HTML页面的链接。

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? 在构建过程中,angular.json是否有办法为生成的css文件创建另一个“副本”并将其拖放到我选择的文件夹中?

As far as "another copy" is concerned, it looks like it's not possible within the angular.json itself. 至于“另一个副本”,似乎在angular.json本身中是angular.json

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. 一个简单的解决方案是制作一个运行该构建程序的npm脚本,然后使用后记脚本复制文件而不添加哈希值。

Eg - package.json 例如-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. cp命令中,您可以将其复制到任何地方。 I just assumed you would want it in the same directory. 我只是假设您想要在同一目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM