更新时间:2023-11-17 21:33:46
当前,我仍然没有找到一种官方的内置方法.
Currently, I still have not found an official built-in way to do so.
我打开了 Angular CLI问题,希望能得到CLI团队的回应
I opened an Angular CLI issue and hopefully will get the CLI team response.
与此同时,我的解决方法是使用命令行工具:
In the meantime my workaround is using command line tools:
在package.json
中我添加了:
"scripts": {
...
"build": "ng build lib1 --prod && scss-bundle -c scss-bundle.config.json && cp -R projects/lib1/src/assets/ dist/lib1/assets/",
}
要复制SASS文件,我将scss-bundle
与包含以下内容的配置文件scss-bundle.config.json
一起使用:
To copy the SASS files I use scss-bundle
with config file scss-bundle.config.json
that contains:
{
"entry": "./projects/lib1/src/assets/style/main.scss",
"dest": "./dist/lib1/assets/style/styles.scss"
}
这会将项目的SASS文件构建为1个文件,并将其复制到dist文件夹中.我的SASS文件结构类似于:
This will build the SASS files of the project into 1 file and copy it into the dist folder. My SASS file structure is something like:
-- projects/lib1/src/assets/
-- style
-- main.scss
-- partials
-- _variables.scss
-- _styles.scss
__ _rtl.scss
因此,正如您所看到的,我不想运送所有原始的sass,而只运送一个最终文件.当然,您也可以将其编译为.css
文件.
So as you can see I don't want to ship all the raw sass, just one final file. Of course, you can also compile it into a .css
file instead.
为确保所有其他资产均被复制,我使用简单的Mac OS/Linux命令cp -R
或rsync
.
To make sure all other assets are copied, I use a simple Mac OS/Linux command cp -R
or rsync
.
当然,我运行的是npm run build
,而不是运行ng build
.
And, of course, instead of running ng build
I run npm run build
.
希望这会有所帮助,如果您有更好的解决方案,请告诉我.
Hope this helps, and if you have a better solution please let me know.