gpt4 book ai didi

javascript - 如何在 Angular 4 中将样式导出为 css 文件

转载 作者:行者123 更新时间:2023-11-30 15:01:01 24 4
gpt4 key购买 nike

我是 Angular 4 的新手,我想将我的样式导出为 css 文件。当我服务或构建元素时,它会创建一个 style.bundle.js 文件并将 css 添加为 html 样式元素。但我想导出为样式表文件并使用 link 元素加载它。

我的 Angular-cli.json :

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ares"
},
"apps": [
{
"name":"desktop",
"root": "src",
"outDir": "dist/desktop",
"assets": [
"assets",
"favicon.ico",
"views/desktop"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"../node_modules/materialize-css/dist/css/materialize.css",
"../node_modules/font-awesome/css/font-awesome.css",
"assets/desktop/css/styles.scss",
"views/desktop/trader/first/assets/css/theme.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/hammerjs/hammer.js",
"../node_modules/materialize-css/dist/js/materialize.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"component": {}
}
}

最佳答案

当您运行 ng buildng serve 时,它总是创建一个像 styles.bundles.js 这样的包,只是为了节省一些时间在开发版本上。另一方面,如果您执行 ng build --prod,它将生成 styles.bundle.css

如果您希望为您的开发构建生成 styles.bundle.css,那么只需添加 --extract-css 标志,例如 ng serve --extract -css.

这里有一些关于默认 flags 的更多细节,可能会有帮助:

enter image description here

关于javascript - 如何在 Angular 4 中将样式导出为 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46532268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com