1

I want to move my angular2 application to Production,using webpack.

    <!DOCTYPE html>
<html>
<head>
  <title>iPage Quick Order</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">  
  <link rel="stylesheet" type="text/css" href="mystyle.css">
  <link rel="stylesheet" type="text/css" href="Stylesheet.css">
  <script src="node_modules/core-js/client/shim.min.js"></script>
  <script src="node_modules/reflect-metadata/Reflect.js"></script>
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>
  <script src="src/script/systemjs.config.js"></script> 
  <script src="node_modules/ng2-bs4-modal/bundles/ng2-bs4-modal.js"></script>
  <script src="node_modules/jquery/dist/jquery.min.js"></script>
  <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script>
      System.import('src/source/app/bootstrap/main').catch(function(err){ console.error(err); });
   </script>
</head>
<body>
  <my-app>Loading...</my-app>
</body>
</html>

My question is that how to add css and js file to web pack Since in prod mode I am getting error, that css and js file not found.

1 Answer 1

1

You can use "HtmlWebpackPlugin", look at the below example:

    //First import this package

    import HtmlWebpackPlugin from 'html-webpack-plugin';

    //Then add this plugin 

     plugins: [
        // Create HTML file that includes reference to bundled JS.
        new HtmlWebpackPlugin({
          template: 'src/index.html',
          inject: true,
        })
      ]

From https://angular.io/docs/ts/latest/guide/webpack.html#!#loaders website:

Webpack generates a number of js and css files. We could insert them into our index.html manually. That would be tedious and error-prone. Webpack can inject those scripts and links for us with the HtmlWebpackPlugin.

Sign up to request clarification or add additional context in comments.

Comments

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.