update @生产区分

This commit is contained in:
huangzhen 2024-11-01 11:58:46 +08:00
parent b7763da877
commit 04da1c5008
8 changed files with 53 additions and 39 deletions

View File

@ -1,13 +1,13 @@
# 营销系统 模版H5
```
### 默认 npm (pnpm 需要注释 webpack.base.js 配置 resolve-modules)
### 依赖包工具 默认 npm (pnpm 需要注释 webpack.base.js 配置 resolve-modules)
npm install
```
### 分支介绍
```
main 开发分支
test 测试分支
main 生产分支
```
### 启动项目
@ -15,12 +15,7 @@ main 开发分支
npm run start
```
### 测试打包
```
npm run dev
```
### 生产打包(推荐)
### 测试/生产打包
```
npm run build
```
@ -35,8 +30,8 @@ npm run build
规范:
目录 /src/views/templates
命名 cmsXxxx
类组件开发 + 外部文件引入样式 (index.scss)
props.comType 1 H5 2 配置页(PC)
"类组件"开发 + 外部文件引入样式 (index.scss)
props.comType: 1 H5; 2 配置页(PC)
cdn 引入图片
注意事项:

View File

@ -1,13 +1,11 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const { DefinePlugin } = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VantResolver } = require('@vant/auto-import-resolver');
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
module.exports = {
entry: path.join(__dirname, '../src/main.ts'), // 入口文件
@ -82,27 +80,11 @@ module.exports = {
dts: path.resolve(__dirname, "../src/components.d.ts"),
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// drop_console: true, // 移除所有的`console`语句
},
output: {
comments: false, // 去掉注释
},
},
extractComments: false, // 不从代码中提取注释
}),
new CssMinimizerPlugin(),
],
},
resolve: {
// 如果用的是pnpm 不要配置这个,会有幽灵依赖的问题,访问不到很多模块
// 查找第三方模块只在本项目的node_modules中查找
modules: [path.resolve(__dirname, '../node_modules')],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: {
'@': path.join(__dirname, '../src')

View File

@ -58,7 +58,7 @@ module.exports = {
new TerserPlugin({
terserOptions: {
compress: {
// drop_console: true, // 移除所有的`console`语句
drop_console: true, // 移除所有的`console`语句
},
output: {
comments: false, // 去掉注释
@ -72,6 +72,7 @@ module.exports = {
// 如果用的是pnpm 不要配置这个,会有幽灵依赖的问题,访问不到很多模块
// 查找第三方模块只在本项目的node_modules中查找
modules: [path.resolve(__dirname, '../node_modules')],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: {
'@': path.join(__dirname, '../src')

View File

@ -1,5 +1,7 @@
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.base.js')
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
// const VITE_BASE_URL = 'http://192.168.110.126:8099'; // 樊波
const VITE_BASE_URL = 'http://120.55.12.245:8098'; // 测试-公网
@ -9,6 +11,23 @@ const VITE_BASE_URL = 'http://120.55.12.245:8098'; // 测试-公网
module.exports = merge(baseConfig, {
mode: 'development', // 开发模式,打包更加快速,省了代码优化步骤
devtool: 'eval-cheap-module-source-map', // 源码调试模式
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// drop_console: true, // 移除所有的`console`语句
},
output: {
// comments: false, // 去掉注释
},
},
// extractComments: false, // 不从代码中提取注释
}),
new CssMinimizerPlugin(),
],
},
devServer: {
port: 8888, // 服务端口号
compress: false, // gzip压缩,开发环境不开启,提升热更新速度

View File

@ -2,6 +2,8 @@ const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.base.js')
const CompressionPlugin = require("compression-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
module.exports = merge(baseConfig, {
mode: 'production', // 生产模式,会开启 tree-shaking 和 压缩代码,以及其他优化
@ -20,6 +22,21 @@ module.exports = merge(baseConfig, {
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true, // 移除所有的`console`语句
},
output: {
comments: false, // 去掉注释
},
},
extractComments: false, // 不从代码中提取注释
}),
new CssMinimizerPlugin(),
],
splitChunks: { // 分隔代码
cacheGroups: {
vendors: { // 提取node_modules 代码

View File

@ -4,9 +4,8 @@
"private": true,
"scripts": {
"start": "cross-env NODE_ENV=development webpack-dev-server --config build/webpack.dev.js",
"dev": "cross-env NODE_ENV=development webpack --config build/webpack.dev.js",
"com": "cross-env NODE_ENV=production webpack --config build/webpack.com.js",
"build": "cross-env NODE_ENV=production webpack --config build/webpack.prod.js"
"build": "cross-env NODE_ENV=production webpack --config build/webpack.prod.js",
"com": "cross-env NODE_ENV=production webpack --config build/webpack.com.js"
},
"dependencies": {
"axios": "^1.7.5",

View File

@ -14,12 +14,12 @@
</noscript>
<div id="app"></div>
<!-- 智能验证防刷 -->
<div id="captcha-element"></div>
<div id="captcha-button"></div>
<!-- <div id="captcha-element"></div>
<div id="captcha-button"></div> -->
<!-- 仅开发/测试使用 -->
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script>
var vConsole = new window.VConsole();
</script>
</script> -->
</body>
</html>

View File

@ -34,7 +34,8 @@
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
"tests/**/*.tsx",
"auto-imports.d.ts"
],
"exclude": [
"node_modules"