Angular-cli: Relative path for assets array in angular-cli.json file not working

Created on 28 Oct 2016  路  6Comments  路  Source: angular/angular-cli

Hi guys,

Using relative path for dealing with assets is not working. For example if I want to use images as my assets from a node module folder.

OS?

Mac OSX Sierra

Versions.

angular-cli: 1.0.0-beta.18
node: 6.8.1
os: darwin x64

Repro steps.

This is what my angular-cli.json file looks like:

{
  "project": {
    "version": "1.0.0-beta.18",
    "name": "project_name"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "build",
      "assets": [
          "assets",
          "../node_modules/my_module/assets"
      ],
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "bootstrap.scss",
        "style.scss"
      ],
      "scripts": [
          "../node_modules/node-uuid/uuid.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
  }
}

The log given by the failure.

No error, just the assets files from the node_modules folder aren't copied to the dist, build for me, one.

Mention any other details that might be useful.

In the case of relative path I think it should copy the files from the specified folder without keeping the hierarchy. Just taking files and folder in it but without recreating the whole hierarchy of folder in the assets folder.

By the way images from the src/assets folder are correctly copied into dist.

So i don't know if it's known or not but I think it can be really useful, for me I'm creating packages for my app and some will have images in them.

Most helpful comment

Instead of just ignoring/doing nothing, could a warning/error be displayed, such as

Attempt to bring in asset outside the project tree

All 6 comments

Btw it's not working for both serveand buildcommand.
I can see the files from the node_modulesfolder being treated as assets when building, but not copied to the dist folder.

This isn't a scenario that we want to support currently. The main reason against it is the final path. The current solution means to _always_ keep your dir structure so that you can reference things via predictable static paths. This just isn't possible if you're looking to have things pulled over from outside the project.

My best recommendation is to copy over those assets to inside the project. If you don't want to have them there in the repo, you can add it to the gitignore.

Sweet.
I ended up using a symlink to do that but if a built-in solution come it will be better.

Instead of just ignoring/doing nothing, could a warning/error be displayed, such as

Attempt to bring in asset outside the project tree

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings