【问题标题】:Include scss path for server side rendering with webpack包含用于使用 webpack 进行服务器端渲染的 scss 路径
【发布时间】:2018-07-18 01:00:35
【问题描述】:

我正在尝试为我的 Angular 5 应用程序(最近从 Angular 4 迁移)部署 Angular Universal,但我遇到了服务器端渲染选项的问题:

ng build --aot --app 1

我在 scss 文件中的变量路径在客户端工作,但在服务器端渲染命令中不工作。我收到了bootstrap-sass 的类似错误

File to import not found or unreadable: bootstrap/variable.

将路径更改为node_modules工作包中的特定路径:

@import '~bootstrap-sass/assets/stylesheets/bootstrap/variables';

我需要修改大约 50 个包含 bootstrap/variable 的文件,但它仍然被接受。但我的代码还包含一个特定的 scss 文件,它因组件而异,如下所示:

@import 'supergazol/footer';

我可以浏览大约 50 个文件来相应地更改它的路径,但这不是很有效且耗时。有没有办法告诉 Webpack 找到正确的路径?

此路径的 Angular CLI 配置不起作用:

"stylePreprocessorOptions": {
        "includePaths": [
          "../node_modules/bootstrap-sass/assets/stylesheets",
          "../src/style/supergazol",
          "../src/style"
        ]
      },

文件夹结构:

src
    app
    assets
    environments
    style

【问题讨论】:

  • 您的应用程序的根设置是什么,在您的 angular-cli.json 中?
  • 目前在"root": "src"
  • 你能显示你的文件夹层次结构吗?尤其是样式文件夹
  • 我更新了我的问题
  • 在您的样式文件夹中,您有一个 supergazol 文件夹,其中包含一个“_footer.scss”文件?你到底得到了什么?

标签: angular webpack angular-universal


【解决方案1】:

试试这个,它可能会有所帮助。我认为您需要在 .angular-cli.json 文件中的两个应用程序中都有它(对于客户端和服务器应用程序)。

"stylePreprocessorOptions": {
        "includePaths": [
          "../node_modules/bootstrap-sass/assets/stylesheets",
          "/style/supergazol",
          "style"
        ]
      },

【讨论】:

  • 对于“两个应用程序” 的说明,在 Angular 7 中,这意味着在同一个 angular.json 文件中,将“stylePreprocessorOptions”添加到位于:项目 > 项目的“服务器”节点-名称>架构师>服务器
猜你喜欢
  • 1970-01-01
  • 2018-07-23
  • 1970-01-01
  • 2021-07-11
  • 2019-02-09
  • 2017-04-04
  • 2018-03-06
  • 2019-02-12
  • 2023-04-01
相关资源
最近更新 更多