123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- const path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
- const filetool = require("./src/utils/file.js")
- const CopyWebpackPlugin = require('copy-webpack-plugin');4
- const entry = {}
- const HTMMLPlugin = []
- const mode = "development"
- const dist_name = "dist-dev"
- const { localPathResult: AllHTMLLocalFile4xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src', 'html', "error", "4xx"))
- AllHTMLLocalFile4xx.forEach((filePath) => {
- if (!filePath.endsWith(".html")) {
- return
- }
- if(filePath.includes("400.html")){
- entry["404"] = path.resolve(__dirname, 'src', '404.js')
- HTMMLPlugin.push(new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', 'html', "error", "4xx", "404.html"), //指定模板文件
- filename: path.join("error", filePath),
- chunks: ["404"]
- }))
- return
- }
- const name = "ck" + filePath.replace(".html", "").replace("/", "-").replace('\\', '-')
- entry[name] = path.resolve(__dirname, 'src', '4xx.js')
- HTMMLPlugin.push(new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', 'html', "error", "4xx", filePath), //指定模板文件
- filename: path.join("error", filePath),
- chunks: [name]
- }))
- })
- const { localPathResult: AllHTMLLocalFile5xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src', 'html', "error", "5xx"))
- AllHTMLLocalFile5xx.forEach((filePath) => {
- if (!filePath.endsWith(".html")) {
- return
- }
- const name = "ck" + filePath.replace(".html", "").replace("/", "-").replace('\\', '-')
- entry[name] = path.resolve(__dirname, 'src', '5xx.js')
- HTMMLPlugin.push(new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', 'html', "error", "5xx", filePath), //指定模板文件
- filename: path.join("error", filePath),
- chunks: [name]
- }))
- })
- module.exports = {
- mode: mode,
- context: __dirname,
- performance: {
- hints: 'warning', // 或者 'error',取决于你希望如何处理超出限制的情况
- maxAssetSize: 5000000, // 设置单个资源的最大尺寸,例如5MB
- maxEntrypointSize: 10000000, // 设置入口起点的最大尺寸,例如10MB
- },
- entry: {
- ...entry,
- index: path.resolve(__dirname, 'src', 'index.js'),
- new: path.resolve(__dirname, 'src', 'new.js'),
- license: path.resolve(__dirname, 'src', 'license.js'),
- mitorg: path.resolve(__dirname, 'src', 'mitorg.js'),
- },
- output: {
- path: path.resolve(__dirname, dist_name), //打包后的文件存放的地方
- filename: 'js/[name].[hash].bundle.js', //打包后输出文件的文件名
- chunkFilename: '[name].bundle.js',
- clean: true,
- publicPath: "./",
- charset: true,
- },
- resolve: {
- alias: {
- "@": path.join(__dirname, "src")
- }
- },
- module: {
- rules: [
- {
- test: /\.css$/,
- use: ['style-loader', 'css-loader']
- },
- {
- test:/\.(png|jpg|jpeg|svg|gif)$/i,
- type: 'asset/resource',
- generator: {
- filename: 'images/[name][ext]'
- }
- },
- {
- test:/\.(png|jpg|jpeg|svg|gif)$/i,
- type: 'asset/resource',
- generator: {
- filename: 'images/[name][ext]'
- }
- },
- {
- test: /\.(woff|woff2|eot|ttf|otf)$/i,
- type: 'asset/resource',
- generator: {
- filename: 'font/[name][ext]'
- }
- },
- {
- test: /\.html$/i,
- loader: "html-loader",
- },
- {
- test: require.resolve("jquery"),
- loader: "expose-loader",
- options: {
- exposes: ["$", "jQuery"],
- },
- },
- ],
- },
- plugins: [
- new CopyWebpackPlugin({
- patterns: [
- { from: 'public', to: './' }, // 这里假设你想将 public 文件夹下的所有内容复制到输出目录的根目录下
- { from: './config.json', to: './SH_CONFIG.json' },
- ],
- }),
- ...HTMMLPlugin,
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html", "index.html"), //指定模板文件
- filename: "index.html",
- chunks: ["index"],
- templateParameters: {
- 'process.env.SH_ICP': JSON.stringify(process.env.SH_ICP),
- 'process.env.SH_WANGAN': JSON.stringify(process.env.SH_WANGAN),
- }
- }),
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html","LICENSE_CN.html"), //指定模板文件
- filename: "LICENSE_CN.html",
- chunks: ["license"]
- }),
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html","LICENSE_EN.html"), //指定模板文件
- filename: "LICENSE_EN.html",
- chunks: ["license"]
- }),
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html","mitorg.html"), //指定模板文件
- filename: "mitorg.html",
- chunks: ["mitorg"]
- }),
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html","index.new.signal.html"), //指定模板文件
- filename: "index.new.signal.html",
- chunks: ["new"]
- }),
- new HtmlWebpackPlugin({
- inject:'body',
- template: path.resolve(__dirname, 'src', "html","index.new.html"), //指定模板文件
- filename: "index.new.html",
- chunks: ["new"]
- }),
- new MiniCssExtractPlugin({
- filename: '[name].[hash].bundle.css',
- chunkFilename: '[id].bundle.css',
- }),
- ],
- devServer: {
- static: {
- directory: path.join(__dirname, dist_name),
- },
- compress: true,
- port: 1001,
- open: true,
- hot: true,
- },
- };
|