Skip to content

Commit

Permalink
fix: 删除html-webpack-plugin的无用属性
Browse files Browse the repository at this point in the history
  • Loading branch information
gz1564 committed Aug 24, 2023
1 parent 5a120b3 commit 92cbe0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
75 changes: 35 additions & 40 deletions config/webpack/webpack.public.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
const path = require("./paths.js")
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('./paths.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackBar = require('webpackbar');
const {
CleanWebpackPlugin
} = require('clean-webpack-plugin');
const webpack = require("webpack");
const UpdateVersionWebpackPlugin = require("./plugins/updateVersion.js");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');
const UpdateVersionWebpackPlugin = require('./plugins/updateVersion.js');
const fs = require('fs');

require('dotenv').config({ path: path.resolveApp("./config/env/.env.public") })
const extraConfig = require('dotenv').parse(fs.readFileSync(path.resolveApp(`./config/env/.env.${process.env.NODE_ENV}`)))
require('dotenv').config({ path: path.resolveApp('./config/env/.env.public') });
const extraConfig = require('dotenv').parse(fs.readFileSync(path.resolveApp(`./config/env/.env.${process.env.NODE_ENV}`)));

for (i in extraConfig) {
process.env[i] = extraConfig[i]
process.env[i] = extraConfig[i];
}

const APP_CNAME = process.env.APP_CNAME
const APP_NAME = process.env.APP_NAME
const APP_CNAME = process.env.APP_CNAME;
const APP_NAME = process.env.APP_NAME;

module.exports = {
output: {
assetModuleFilename: "images/[hash][ext]", // 将png,jpg,jpeg,gif等资源文件存放到images下。
assetModuleFilename: 'images/[hash][ext]', // 将png,jpg,jpeg,gif等资源文件存放到images下。
library: `${APP_CNAME}-[name]`,
chunkFilename: '[name].[contenthash].js',
// 需要配置成 umd 规范
Expand All @@ -30,68 +28,65 @@ module.exports = {
// webpack5 使用 chunkLoadingGlobal 代替,或不填保证 package.json name 唯一即可
chunkLoadingGlobal: 'garfish-demo',
},
entry: [
path.resolveApp("./src/index")
],
entry: [path.resolveApp('./src/index')],
resolve: {
extensions: [".ts", ".tsx", ".jsx", ".js", ".json"], // 无需后缀即可完成导入
extensions: ['.ts', '.tsx', '.jsx', '.js', '.json'], // 无需后缀即可完成导入
alias: {
"@": path.resolveApp("./src/pages"),
"@src": path.resolveApp("./src"),
"@config": path.resolveApp("./config"),
"@store": path.resolveApp("./store"),
'@': path.resolveApp('./src/pages'),
'@src': path.resolveApp('./src'),
'@config': path.resolveApp('./config'),
'@store': path.resolveApp('./store'),
},
// webpack 5 不再自动 polyfill Node.js 的核心模块,这意味着如果你在浏览器或类似的环境中运行的代码中使用它们,你必须从 NPM 中安装兼容的模块,并自己包含它们 https://webpack.docschina.org/configuration/resolve/#resolvefallback
fallback: {
"path": require.resolve("path-browserify"),
path: require.resolve('path-browserify'),
},
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
include: [path.resolveApp("src"), path.resolveApp("config"), path.resolveApp("store")],
exclude: [path.resolveApp("node_modules")],
loader: "esbuild-loader",
include: [path.resolveApp('src'), path.resolveApp('config'), path.resolveApp('store')],
exclude: [path.resolveApp('node_modules')],
loader: 'esbuild-loader',
options: {
target: "es2015"
target: 'es2015',
},
},
{
test: /\.(png|jpg|jpeg|gif)$/,
type: "asset/resource",
type: 'asset/resource',
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
}
]
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser'
process: 'process/browser',
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env)
'process.env': JSON.stringify(process.env),
}),
// 清除dist目录
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: APP_CNAME,
mountRoot: APP_NAME,
template: path.resolveApp("./src/index.html"),
filename: "index.html",
template: path.resolveApp('./src/index.html'),
filename: 'index.html',
inject: 'body', // 所有javascript 资源都是加载到body底部
htmlContent: '<%- __html__ %>',
initialData: 'window.__INITIAL_STATE__ = <%- __state__ %>',
hash: true, // 为静态资源生成hash值
minify: { // 压缩HTML文件
minify: {
// 压缩HTML文件
removeComments: false, // 移除HTML中的注释
collapseWhitespace: false, // 删除空白符与换行符
},
favicon: path.resolveApp('./config/public/favicon.ico')
favicon: path.resolveApp('./config/public/favicon.ico'),
}),
new WebpackBar(), // 进度条
new UpdateVersionWebpackPlugin({})
]
}
new UpdateVersionWebpackPlugin({}),
],
};
9 changes: 3 additions & 6 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
important: true,
content: [
"./src/**/*.{js,ts,jsx,tsx}"
],
important: '#demo',
content: ['./src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
corePlugins: {
preflight: false,
},
plugins: [],
}

};

0 comments on commit 92cbe0b

Please sign in to comment.