Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get angular 2 cli to copy css and other necessary files to dist folder

Tags:

I have set up an angular 2 typescript solution and added the material angular 2 npm package.

npm install -g angular-cli
ng new PROJECT_NAME
cd PROJECT_NAME
ng build

Everything is nicely copied from my scaffolded source folder to a dist folder.

Then I add the angular 2 material npm package:

npm install ng2-material --save

But what do I do from here? How do I tell the build command to copy the necessary files from node_modules to the dist folder.

And where is the magic located that makes sure that these files get copied to the dist/vendor folder?

<body>
  <timer-app>Loading...</timer-app>

  <script src="vendor/es6-shim/es6-shim.js"></script>
  <script src="vendor/systemjs/dist/system-polyfills.js"></script>
  <script src="vendor/angular2/bundles/angular2-polyfills.js"></script>
  <script src="vendor/systemjs/dist/system.src.js"></script>
  <script src="vendor/rxjs/bundles/Rx.js"></script>

  <script src="vendor/angular2/bundles/angular2.dev.js"></script>
  <script src="vendor/angular2/bundles/http.dev.js"></script>
  <script src="vendor/angular2/bundles/router.dev.js"></script>
...

My package file ends up looking like this: https://gist.github.com/nikolaj-kaplan/e85d5805fd67c3ba3f1f

I hope my confusion comes from a lack of knowledge about npm. And not angular cli. (Because more people will be able to help me). But I haven't got a whole lot of experience in either.

Edit:

I did like this: https://stackoverflow.com/a/35900837/564623

module.exports = function (defaults) {
  var app = new Angular2App(defaults, {
      vendorNpmFiles: [
          'node_modules/ng2-material/dist/ng2-material.css'
      ]
  });
  return app.toTree();
}

Now my files are copied. Still don't understand how the other files in the dist-folder gets copied. The vendorNpmFiles array was empty.

like image 452
Nikolaj Avatar asked Mar 11 '16 19:03

Nikolaj


1 Answers

You don't need node_modules/ prefix, vendorNpmFiles automatically search in node_modules

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'ng2-material/dist/ng2-material.css'
    ]
  });
};
like image 156
Antoine Avatar answered Oct 12 '22 01:10

Antoine