项目资源设置

作者: 王义杰 | 来源:发表于2018-06-08 10:52 被阅读16次

项目资产

You use the assets array in .angular-cli.json to list files or folders you want to copy as-is
when building your project.
你使用 angular.json 里面的 assets 文件或目录列表,当构建你的项目时原样复制。

By default, the src/assets/ folder and src/favicon.ico are copied over.
默认,src/assets 文件夹和 src/favicon.io 是会复制的。

"assets": [
  "assets",
  "favicon.ico"
]

You can also further configure assets to be copied by using objects as configuration.
你总能进一步复制配置资产使用项目配置文件。

The array below does the same as the default one:
下面的数组与默认值相同:

"assets": [
  { "glob": "**/*", "input": "./assets/", "output": "./assets/" },
  { "glob": "favicon.ico", "input": "./", "output": "./" },
]

glob is the a node-glob using input as base directory.
glob 是一个 node-glob 使用 input 做为根目录.

input is relative to the project root (src/ default), while output is
relative to outDir (dist default).
input 相对于项目的根 (src/ 默认), 而 output 是相对于
outDir (dist 默认).

You can use this extended configuration to copy assets from outside your project.
For instance, you can copy assets from a node package:
你能使用扩展配置复制项目外面的资产。例如,你能复制一个node包:

"assets": [
 { "glob": "**/*", "input": "../node_modules/some-package/images", "output": "./some-package/" },
]

The contents of node_modules/some-package/images/ will be available in dist/some-package/.
内容 node_modules/some-package/images/dist/some-package/ 是有效的.

Writing assets outside of dist/

存放资产在 dist/ 外面

Because of the security implications, the CLI will always refuse to read or write files outside of
the project itself (scoped by .angular-cli.json). It is however possible to write assets outside
the dist/ build output folder during build.
因为涉及安全,CLI总是拒绝读或写它自身项目(由描述 .angular-cli.json)外的文件。然后它在构建的时可能写在的 dist/ 外的。

Because writing files in your project isn't an expected effect of ng build, it is disabled by
default on every assets. In order to allow this behaviour, you need to set allowOutsideOutDir
to true on your asset definition, like so:
因为写文件在你的项目不是 ng build 预期的结果,它在资产上默认是关闭的,为了允许这种行为,你需要在你的资产定义设置 allowOutsideOutDirtrue ,想这样:

"assets": [
  {
    "glob": "**/*",
    "input": "./assets/",
    "output": "../not-dist/some/folder/",
    "allowOutsideOutDir": true
  },
]

This needs to be set for every assets you want to write outside of your build output directory.
你需要设置此项为你想要输出在你构建目录外的每个资产。

相关文章

网友评论

    本文标题:项目资源设置

    本文链接:https://www.haomeiwen.com/subject/dhiosftx.html