stackdave
stackdave

Reputation: 7094

angular-cli for webpack does not really work

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?

Upvotes: 0

Views: 739

Answers (2)

stackdave
stackdave

Reputation: 7094

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.

Upvotes: 0

Mark Leong
Mark Leong

Reputation: 1528

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": "+"
  }
}

Upvotes: 1

Related Questions