0

I'm using "angular-cli": "1.0.0-beta.11-webpack.2"

my angular-cli-build.js I have:

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(ts|js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      '@angular/**/*.+(js|js.map)',
      'bootstrap/dist/css/bootstrap.css'
    ]
  });
};

and my index.html:

<link rel="stylesheet" type="text/css" href="vendor/bootstrap/dist/css/bootstrap.min.css">

but with ng build, i get nothing in /dist folder... how this does work exactly with webpack? I used to work easy with webpack and angular 1, now i see it's really complicated and i wasting a lot of time trying to guess how that must work, and i see angular-cli is just for test, not for real work? there is a way to replace angular-cli compile to override it with webpack in the old way?

2
  • my advice, it's not use angular-cli for real work or simple app , you can spend a lot of days and hours simply trying install. version that don't use webpack is not professional and very unstable, so for real production better look for a starter and do the things manually, you will save a lot of hours and days like I had to do. Commented Aug 31, 2016 at 9:58
  • version for Web pack is dark, you are prisoner, things and config is inside the core and not in a simple Web pack config, you are prisoner of beta versions and decisions of programmers , i'm not going to use it at least for this year Commented Aug 31, 2016 at 10:06

2 Answers 2

1

If you upgrade to 1.0.0-beta.11-webpack.3 or higher, you can use the apps[0].styles property of angular-cli.json to list external stylesheets for import. With this you don't have to add anything to index.html.

To upgrade from 1.0.0-beta.11-webpack.2, run:

npm uninstall -g angular-cli
npm cache clean
npm install -g [email protected]

From https://github.com/angular/angular-cli#updating-angular-cli, the additional steps to run in your project directory when upgrading an existing project are:

rm -rf node_modules dist tmp
npm install --save-dev angular-cli@latest
ng init

If you generate a new project and install Bootstrap, your angular-cli.json should look something like this:

{
  "project": {
    "version": "1.0.0-beta.11-webpack.3",
    "name": "demo"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": "assets",
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "dev": "environments/environment.dev.ts"
      }
    }
  ],
  "addons": [],
  "packages": [],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false,
    "lazyRoutePrefix": "+"
  }
}
Sign up to request clarification or add additional context in comments.

13 Comments

Different guy, same problem -- I tried upgrading to webpack.3 and it didn't fix my issue of loading global styles. I updated my angular-cli.json file to look like what you show as well. Are there other files that need changes? Or should I just start over with a new project and copy my existing code over? Thanks in advance!
@TheManiac to upgrade an existing project see the steps here: github.com/angular/angular-cli#updating-angular-cli
@TheManiac angular-cli@latest will give you 1.0.0-beta.11-webpack.8 at the moment. You can run npm dist-tag ls angular-cli to see what the current @latest distribution tag points to.
@TheManiac you're right, my bad! angular-cli@latest gives you 1.0.0-beta.10, which isn't the webpack one. angular-cli@webpack gives you 1.0.0-beta.11-webpack.8 (the latest webpack version), which I found more buggy than 1.0.0-beta.11-webpack.3 hence my the version recommended in my answer.
@TheManiac it sounds like this issue with typscript 2.0.2. Changing changing "typescript": "^2.0.0" to "typescript": "2.0.0" in package.json and running npm install fixed it for me.
|
0

I've found that work with angular-cli is very unstable, it's better to use a webstarte and do the things manually , angular 2 release candidate is changing yet this year and the things are slow, worst for angular-cli

https://github.com/preboot/angular2-webpack

Steps to work with bootstrap4 css:

1. npm install --save bootstrap@^4.0.0-alpha.3
2. in app.component.ts just insert:

import 'bootstrap/dist/css/bootstrap.css';

and everything is magic and working:

everything is automatic and have no problems like with angular-cli, i don't advice use this last to build the app, just to generate componentes or thinks like that; angular-cli is really very beta state development.

1 Comment

Anyone who comes across this in the future, we should state that the angular-cli has come a long way and is now also the "recommended" tool to use during angular development. To answer the original question you can add assets in your angular directly into your angular-cli.json config file. Have a look at the default one when you type in ng new [project name] for a clean example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.