如何告诉构建包含更多文件

时间:2016-12-03 12:13:53

标签: javascript angular angular-cli

我正在尝试构建我的应用程序,但ng build命令并未包含所有文件,例如styles.css或图像或库,例如c3.js或{{ 1}}。

我可以通过将这些文件复制并粘贴到d3.js文件夹(文件位于dist命令之后)来完成此操作,但这样做效率很低,因为我每次都要这样做ng build

如何让ng build自动包含样式,图像和库。

修改 ng build档案:

angular-cli.json

出现以下错误,因为{ "project": { "version": "1.0.0-beta.20-4", "name": "scada-lts-ui" }, "apps": [ { "root": "src", "outDir": "dist", "assets": [ "assets", "favicon.ico" ], "index": "index.html", "main": "main.ts", "test": "test.ts", "tsconfig": "tsconfig.json", "prefix": "app", "mobile": false, "styles": [ "styles.css" ], "scripts": [ "../node_modules/hammerjs/hammer.min.js" ], "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } } ], "addons": [], "packages": [], "e2e": { "protractor": { "config": "./protractor.conf.js" } }, "test": { "karma": { "config": "./karma.conf.js" } }, "defaults": { "styleExt": "css", "prefixInterfaces": false, "inline": { "style": false, "template": false }, "spec": { "class": false, "component": true, "directive": true, "module": false, "pipe": true, "service": true } } } 不会从app目录复制这些文件。

enter image description here

1 个答案:

答案 0 :(得分:4)

将您的文件添加到" assets" -array中的angular-cli.json https://github.com/angular/angular-cli#project-assets

这将包括assets-folder(按原样)和favicon.ico -file

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

如果您希望js和css文件在构建

中进行共享

然后将所需的脚本文件添加到apps [0] .scripts:

"scripts": [
  "../node_modules/jquery/dist/jquery.js",
  "../node_modules/tether/dist/js/tether.js",
  "../node_modules/bootstrap/dist/js/bootstrap.js"
],

最后将Bootstrap CSS添加到apps [0] .styles array:

"styles": [
  "../node_modules/bootstrap/dist/css/bootstrap.css",
  "styles.css"
],

捆绑文件在构建时从index.html自动链接, 您需要在您的代码中提供链接的assets-array包含的文件和文件夹。

看看自述文件的这一部分 https://github.com/angular/angular-cli#3rd-party-library-installation