Ts-loader packages more slowly after using happypack

ts-loader packages more slowly after using happypack
the code is as follows

const path = require("path");
const fs = require("fs");
const lessToJs = require("less-vars-to-js");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const env = process.argv.slice(-1)[0];

const devUrlLoader = "url-loader?limit=8192&name=[hash:8].[name].[ext]";
const prodUrlLoader = "url-loader?limit=8192&name=[hash:8].[name].[ext]&outputPath=assets/images/&publicPath=assets/images";

// antd
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, "../src/assets/style/theme.less"), "utf8"));

module.exports = {
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          {
            // loader: "happypack/loader?id=js",
            loader: "babel-loader",
          },
          {
            // loader: "happypack/loader?id=ts",  // 
            loader: "ts-loader",
          },
        ],
        include: [
          path.join(__dirname, "../src"),
        ],
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "happypack/loader?id=js",
            // loader: "babel-loader",
          },
        ],
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          use: [{
            loader: "css-loader",
          }],
          fallback: "style-loader",
        }),
      },
      {
        test: /\.sass$/,
        use: ["style-loader", "css-loader", "sass-loader?outputStyle=expanded&indentedSyntax"],
      }, {
        test: /\.scss$/,
        use: ["style-loader", "css-loader", "sass-loader?outputStyle=expanded"],
      },
      {
        test: /\.less$/,
        exclude: /node_modules/,
        use: ExtractTextPlugin.extract({
          use: [{
            loader: "happypack/loader?id=less_src", // 
          }],
          fallback: "style-loader",
        }),
      },
      {
        test: /\.less$/,
        exclude: /src/,
        use: ExtractTextPlugin.extract({
          use: [{
            loader: "happypack/loader?id=less_node_modules", // 
          }],
          fallback: "style-loader",
        }),
      },
      {
        test: /\.(png|jpe?g|gif|woff|woff2|ttf|eot)$/,
        loader: env === "development" ? devUrlLoader : prodUrlLoader,
      },
      {
        test: /\.svg$/,
        loader: "svg-sprite-loader",
      },
    ],
  },
  plugins: [

  ],
  resolve: {
    modules: [
      path.resolve(__dirname, "../src"),
      "node_modules",
    ],
    extensions: [".js", ".json", ".jsx", ".ts", ".tsx"],
    alias: {
      src: path.resolve(__dirname, "../src/"),
    },
  },
};


const path = require("path");
const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const merge = require("webpack-merge");
const lessToJs = require("less-vars-to-js");
const fs = require("fs");

// happypack 
const HappyPack = require("happypack");
const os = require("os");

const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const commonConfig = require("./webpack.base.js");

// antd
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, "../src/assets/style/theme.less"), "utf8"));

module.exports = function (env) {
  return merge(commonConfig, {
    cache: true,
    devtool: "cheap-module-eval-source-map",
    entry: {
      bundle: [
        "react-hot-loader/patch",
        "webpack-dev-server/client?http://localhost:8000",
        "webpack/hot/only-dev-server",
        "./src/index.tsx",
      ],
      vendor: ["react", "react-dom"],
      lib: ["antd"],
    },
    output: {
      path: path.join(__dirname, "/../dist/assets"),
      filename: "[name].js",
      publicPath: "/assets/",
      sourceMapFilename: "[name].map",
    },
    devServer: {
      historyApiFallback: true,
      noInfo: false,
      hot: true,
      open: true,
      stats: "minimal",
      contentBase: "./src/",
      publicPath: "/assets/",
      compress: true,
      port: 8000,
      proxy: {
        "/api/*": {
          target: "http://localhost:9090",
          secure: false,
          changeOrigin: true,
        },
      },
    },
    optimization: {
      runtimeChunk: {
        name: "manifest",
      },
    },
    plugins: [
      new webpack.HotModuleReplacementPlugin(),
      new ExtractTextPlugin({
        filename: "style.css",
        disable: false,
        allChunks: true,
      }),
      new HappyPack({
        id: "ts",
        threadPool: happyThreadPool,
        loaders: [
          {
            path: "ts-loader",
            query: { happyPackMode: true, transpileOnly: true },
          },
        ],
      }),
      new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
      new HappyPack({
        id: "js",
        loaders: ["babel-loader"],
        threadPool: happyThreadPool,
      }),
      new HappyPack({
        id: "less_src",
        loaders: [{
          loader: "css-loader",
          options: {
            importLoaders: 1,
            modules: true,
            namedExport: true,
            camelCase: true,
            localIdentName: "[path][name]__[local]--[hash:base64:5]",
          },
        }, {
          loader: "postcss-loader",
        },
        {
          loader: "less-loader",
          options: {
            javascriptEnabled: true,
            modifyVars: themeVariables,
          },
        }],
        threadPool: happyThreadPool,
      }),
      new HappyPack({
        id: "less_node_modules",
        loaders: [{
          loader: "css-loader",
          options: {
            importLoaders: 1,
          },
        }, {
          loader: "postcss-loader",
        },
        {
          loader: "less-loader",
          options: {
            javascriptEnabled: true,
            modifyVars: themeVariables,
          },
        }],
        threadPool: happyThreadPool,
      }),
    ],
  });
};

      

I don"t understand why, but the packing is slower, so I have the wrong configuration.

this is my project. The complete code is here
https://github.com/wanliyunya.

.

2018-8-9
not only is the ts slower, but the packaging less style is also slower. I think it"s my configuration problem! The gods take a look at it for me

Apr.23,2021

is probably not a problem of configuration. If several projects are used, the speed will slow down as long as happypack is used. The best way to optimize the construction speed is always to split the basic code


. Is

slow for the first time or is it slow every time you change the file? One of the principles of happypack acceleration is caching, but this is based on the fact that your dependency is relatively clear. Dependency clarity means that import, should not be used when import, is particularly complex, which may affect the cache hit rate.

although I don't bother with webpack now, the overall feeling from 1.0 to 3.0 is that if you want to improve the build speed, it is enough to use some of the best practices provided by webpack, such as CommonChunk, resolve, alias, etc., in addition to the configuration itself, it also has a lot to do with the way you write code, and a good code organization is also conducive to automatic optimization of the build tool.

on this basis, using a plug-in like happypack is just the icing on the cake, and it won't instantly improve your development experience by an order of magnitude.

I hope it will be helpful.


replacing ts-loader with awesome-typescript-loader can improve packaging speed.


ts-loader options add transpileOnly: true ;
then use fork-ts-checker-webpack-plugin to process tslint check;
speed up is very obvious.


your configuration is wrong. You give two asynchronous loader; processes in a tsx processor. One tsx file is first converted into jsx with ts-loader and then into js; with babel-loader. This should be a complete combination of functions. This combination is the smallest unit of multithreading that ensures complete execution
const happyTsx = new happyPack ({

.
id:"happy-tsx"
loaders:["babel-loader","ts-loader"]

})


https://juejin.im/post/5cc813.. If you are interested, you can refer to this link. The speed has indeed improved a lot

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38597-2b883.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38597-2b883.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?