运管 - plugin 配置

HtmlWebpackPlugin

 new HtmlWebpackPlugin({
    isDev v: process.env.NODE_ENV === 'development',
    filename: 'index.html',
    template: './client/views/index.ejs',
  })

https://webpack.docschina.org/plugins/html-webpack-plugin/#root

当 webpack 打包时,会创建一个 html 文件,并把 webpack 打包后的静态文件自动插入到这个 html 文件中

  • template:指定你生成的文件依赖哪一个 html 文件模板,模板类型可以是 html、ejs 等
//index.ejs
<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>xxxxxx</title>
</head>

<body class="pbm">
  <div id="app"></div>
</body>
<% if (htmlWebpackPlugin.options.isDev){ %>
<script src="https://cdn-health.xx.com/library/react/v16.10.2/react.development.js"></script>
<script src="https://cdn-health.xx.com/library/react-dom/v16.10.2/react-dom.development.js"></script>
<script src="https://cdn-health.xx.com/library/react-router/v5.1.2/react-router-dom.js"></script>
<% } else { %>
<script src="https://cdn-health.xx.com/library/react/v16.10.2/react.production.min.js"></script>
<script src="https://cdn-health.xx.com/library/react-dom/v16.10.2/react-dom.production.min.js"></script>
<script src="https://cdn-health.xx.com/library/react-router/v5.1.2/react-router-dom.min.js"></script>
 <% } %>
</html>

MiniCssExtractPlugin

new MiniCssExtractPlugin({
    filename: "[name].[contenthash:8]css",
    chunkFilename: "[id].[contenthash:8].css"
})

https://webpack.docschina.org/plugins/mini-css-extract-plugin#root

会生成 css 文件,并在 html 中以 <link> 方式进行引入,使用方法如下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容