const os = require("os");
const path = require("path");
const ESLintWebpackPlugin = require("eslint-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const threads = os.cpus().length;
const getStyleLoaders = (preProcessor) => {
return [MiniCssExtractPlugin.loader, "css-loader", {
loader: "postcss-loader", options: {
postcssOptions: {
plugins: ["postcss-preset-env",
],
},
},
}, preProcessor,].filter(Boolean);
}; module.exports = {
entry: "./src/main.js", output: {
path: path.resolve(__dirname, "../dist"),
filename: "static/js/main.js",
clean: true,
}, module: {
rules: [{
oneOf: [{
test: /\.css$/,
use: getStyleLoaders(),
}, { test: /\.less$/, use: getStyleLoaders("less-loader"), },
{ test: /\.s[ac]ss$/, use: getStyleLoaders("sass-loader"), },
{ test: /\.styl$/, use: getStyleLoaders("stylus-loader"), }, {
test: /\.(png|jpe?g|gif|webp)$/, type: "asset", parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
}, generator: {
filename: "static/imgs/[hash:8][ext][query]",
},
},
{ test: /\.(ttf|woff2?)$/, type: "asset/resource", generator: { filename: "static/media/[hash:8][ext][query]", }, },
{
test: /\.js$/,
include: path.resolve(__dirname, "../src"),
use: [{
loader: "thread-loader",
options: {
workers: threads,
},
}, {
loader: "babel-loader", options: {
cacheDirectory: true,
},
},],
},],
},],
}, plugins: [new ESLintWebpackPlugin({
context: path.resolve(__dirname, "../src"),
exclude: "node_modules",
cache: true,
cacheLocation: path.resolve(__dirname, "../node_modules/.cache/.eslintcache"), threads,
}), new HtmlWebpackPlugin({
template: path.resolve(__dirname, "../public/index.html"),
}),
new MiniCssExtractPlugin({
filename: "static/css/main.css",
}),
new CssMinimizerPlugin(),], optimization: {
minimize: true, minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
parallel: threads
})],
},
devServer: {
host: "localhost",
port: "3000",
open: true,
},
mode: "production",
devtool: "source-map",
};
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探