Angular 2 webpack systemjs.config.js脚本和CSS问题



我想使用webpack将Angular2应用程序移至生产。

    <!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>

我的问题是如何将CSS和JS文件添加到Web Pack由于在产品模式下,我会遇到错误,因此找不到CSS和JS文件。

您可以使用" htmlwebpackplugin",请查看以下示例:

    //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,
        })
      ]

来自https://angular.io/docs/ts/latest/guide/webpack.html#! #loaders网站:

WebPack生成许多JS和CSS文件。我们可以将它们插入我们的索引中。那将是乏味且容易出错的。WebPack可以向我们注入这些脚本和链接。

最新更新