• webpack小记


    1.配置babel

    npm i @babel/core @babel/preset-env babel-loader -D

     2.配置react

    npm i react react-dom @babel/preset-react -D

     

     3.配置css-loader

    npm i style-loader css-loader -D

     4.配置less-loader

    npm i less less-loader -D

     5.配置file-loader url-loader

    npm i file-loader url-loader -D

    6.热更新 webpack-dev-server

    npm i webpack-dev-server -D

     7.提取css出来 mini-css-extract-plugin

    npm i mini-css-extract-plugin -D

     

     跟css相关的都要加上 MiniCssExtractPlugin.loader

    8.css压缩  optimize-css-assets-webpack-plugin

    npm i optimize-css-assets-webpack-plugin cssnano -D

     

     9.配置 html-webpack-plugin

    npm i html-webpack-plugin -D

     10.清空dist目录 clean-webpack-plugin

    npm i clean-webpack-plugin -D

     

     11.前缀自动补全  postcss-loader autoprefixer

    npm i postcss-loader autoprefixer -D

     

     12.将px转化成rem  

    npm i px2rem-loader -D
    npm i lib-flexible -S

     

     13.内联标签

    npm i raw-loader@0.5.1 -D

     14.配置glob 动态配置多页面打包

    npm i glob -D
    const setMPA = () => {
      const entry = {};
      const htmlWebpackPlugins = [];
      const entryFiles = glob.sync(path.resolve(__dirname, "./src/*/index.js"));
      Object.keys(entryFiles).map(index => {
        const entryFile = entryFiles[index];
        const match = entryFile.match(/src/(.*)/index.js/);
        const pageName = match && match[1];
        entry[pageName] = entryFile
        htmlWebpackPlugins.push(new HtmlWebpackPlugin({
          template: path.resolve(__dirname, `src/${pageName}/index.html`),
          filename: `${pageName}.html`,
          chunks: [pageName],
          inject: true,
          minify: {
            html5: true,
            collapseWhitespace: true,
            preserveLinBreaks: false,
            minifyCSS: true,
            minifyJS: true,
            removeComments: false
          }
        }))
      });
      return {
        entry,
        htmlWebpackPlugins
      }
    };
    const { entry, htmlWebpackPlugins } = setMPA();

     15.html-webpack-externals-plugin 配置

    npm i html-webpack-externals-plugin -D

     

     16.splitChunks的使用

    16.1引入第三方库

     16.2 公共模块

     17.代码分割,动态import

    npm i @babel/plugin-syntax-dynamic-import -D

     

     18.

  • 相关阅读:
    STL的适配器、仿函数学习之一:accumulate和for_each的使用心得
    百度笔试题--------数字拼接,求出最小的那个
    百度面试题----依概率生成
    百度笔试题----C语言版revert
    百度笔度题-----蚂蚁爬杆问题
    Try....Catch......Finally 的执行顺序
    数据库SQL SERVER 2008R2 远程连接配置说明
    C#中的数据库的连接方式分类说明(转载)
    网络通信—udp使用领悟
    (转载)C#网络通信之TCP连接
  • 原文地址:https://www.cnblogs.com/chenmiaosong/p/11997716.html
Copyright © 2020-2023  润新知