phantasmal-world/webpack.prod.js

102 lines
2.9 KiB
JavaScript

const common = require("./webpack.common.js");
const antd_theme = require("./antd_theme.js");
const path = require("path");
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Dotenv = require("dotenv-webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = merge(common, {
mode: "production",
output: {
filename: "[name].[contenthash].js",
},
optimization: {
moduleIds: "hashed",
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
styles: {
name: "style",
test: /\.(css|less)$/,
chunks: "all",
enforce: true,
},
vendor: {
test: /node_modules/,
name: "vendors",
chunks: "all",
},
},
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
include: path.resolve(__dirname, "src"),
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[local]--[hash:base64:5]",
},
},
},
],
},
{
test: /\.css$/,
include: /node_modules/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.less$/,
include: /antd/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "less-loader",
options: {
javascriptEnabled: true,
modifyVars: antd_theme,
},
},
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"],
},
{
test: /\.worker\.js$/,
use: { loader: "worker-loader" },
},
],
},
plugins: [
new CleanWebpackPlugin(),
new Dotenv({
path: "./.env.prod",
}),
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, "assets"),
to: path.resolve(__dirname, "dist/assets"),
},
]),
],
});