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