【问题标题】:Changing directory structure in an angular-cli project更改 angular-cli 项目中的目录结构
【发布时间】:2016-10-31 14:28:48
【问题描述】:

我一直在研究 angular-cli 以决定是否要将其用作我们正在开始的新项目的基础。我们在 Microsoft 商店工作了很长时间,并且主要掌握服务器端知识,因此我们正在尽最大努力学习客户端框架世界的来龙去脉。我们喜欢 angular-cli 项目,因为它内置了测试、捆绑、摇树等功能,保留这些功能是我提出问题的原因。我们遇到了更改默认目录结构的需要。我们使用 MVC 来提供一个视图,该视图基本上是 Angular 应用程序的 index.html 文件。如果我们使用标准的 angular-cli 项目文件夹结构执行此操作,则应用程序不会运行或构建,因为所有路径引用都在寻找 .\src\app...

我需要知道的是,我需要在 angular-cli 设置中进行哪些更改,以便 cli 的自动监视、构建、绑定、测试等功能继续使用这个新结构,或者,这是不是我们想要挖掘的东西,因为它会在未来破裂?

【问题讨论】:

    标签: angular angular-cli


    【解决方案1】:

    angular-cli 中有很多自定义选项,您可以通过更新 angular-cli.json 文件来实现。

        "root": "src",
        "outDir": "dist",
        "assets": [
            "assets"
          ],
          "index": "index.html",
          "main": "main.ts",
          "test": "test.ts",
          "tsconfig": "tsconfig.json",
          "prefix": "",
          "mobile": false,
          "styles": [
    
          ],
          "scripts": [
    
          ],
          "environments": {
            "source": "environments/environment.ts",
            "dev": "environments/environment.ts",
            "prod": "environments/environment.prod.ts"
          }
        }
    

    大多数配置都是不言自明的,您可以使用这些来实现您的需要。

    希望这会有所帮助!

    【讨论】:

    • Madhu,我认为这会有所帮助,但是当我尝试修改“root”配置元素的值时,我在构建过程中开始出现错误。我将其设置为根文件夹名称“bt2.web”。错误是:C:\dev\ph\git\BT2\bt2.web\bt2.web\main.ts 不存在
    • 你有没有试过给你的网络文件夹的名字,你也必须记住所有的路径都是相对于根变量的。
    • 根路径条目是否相对于 angular-cli.json 文件?
    • 经过多次尝试,我得出的结论是 angular-cli 在太多地方假定默认项目文件夹结构,我无法轻松更改它。我并不是说这不可能,只是不像在配置中更改根文件夹的名称那么简单。感谢马杜的帮助!
    • 你试过设置"root": "./"吗?如果它实际上接受相对路径,则应该在您的情况下这样做。
    【解决方案2】:

    你试过ng init --source-dir吗?

    PS C:\Users\andre\Workspace\myproject> ng init --help
    
    ng init <glob-pattern> <options...>
      Creates a new angular-cli project in the current folder.
      aliases: u, update, i
      --dry-run (Boolean) (Default: false)
        aliases: -d
      --verbose (Boolean) (Default: false)
        aliases: -v
      --link-cli (Boolean) (Default: false)
        aliases: -lc
      --skip-npm (Boolean) (Default: false)
        aliases: -sn
      --skip-git (Boolean) (Default: false)
        aliases: -sg
      --skip-tests (Boolean) (Default: false)
        aliases: -st
      --skip-commit (Boolean) (Default: false)
        aliases: -sc
      --name (String) (Default: )
        aliases: -n <value>
      --source-dir (String) (Default: src)
        aliases: -sd <value>
      --style (String) (Default: css)
      --prefix (String) (Default: app)
        aliases: -p <value>
      --routing (Boolean) (Default: false)
      --inline-style (Boolean) (Default: false)
        aliases: -is
      --inline-template (Boolean) (Default: false)
        aliases: -it
    

    【讨论】:

      猜你喜欢
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多