0

I was starting an angular 2 project with webpack.I am using angular2-webpack-starter https://github.com/AngularClass/angular2-webpack-starter.

I want to include external javascripts and css in my app.I have checked some blogs but I found them confusing.

2
  • What do you mean by external? What have you tried so far Commented Aug 23, 2016 at 9:24
  • I mean any javascript file like jquery,chartjs etc Commented Aug 23, 2016 at 12:06

1 Answer 1

1

I'm guessing by external css and js you mean downloaded files that you have in your project somewhere. If you've used the webpack starter seed as is you most likely have an assets folder inside src/ thats already set up for you to place external css and js files in and list them in the index.html file.

If not, either redownload the seed if you want to start again, or you can create this folder under src, and include the files in the index.html file, something like

<script src="/assets/css/lib.min.css" />
<script src="/assets/js/lib.min.js" />

If you are bundling using webpack then you will also need to tell webpack to move the assets folder to the create location. In webpack.config.js you can do the following:

const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    ...
    plugins: [
        new CopyWebpackPlugin([
            { from: 'src/assets', to 'assets' }
        ]),
        ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

This answer has been downvoted with no explanation why - isn't helpful whatsoever
Works for me, using angular-cli "ng serve". (Also, upvoted this answer just 'cause.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.