-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vue2多打包vite/rspack/webpack (#171)
* feat: vue2多打包vite/rspack/webpack * fix: 检视意见修改
- Loading branch information
Showing
14 changed files
with
429 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/toolkits/pro/template/tinyvue2/config/vite.config.dev.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { mergeConfig } from 'vite'; | ||
import baseConfig from './vite.config.base'; | ||
|
||
const proxyConfig = { | ||
'/api': { | ||
target: 'http://127.0.0.1:3000', | ||
changeOrigin: true, | ||
rewrite: (path) => path.replace(/^\/api/, ''), | ||
}, | ||
'/mock': { | ||
target: 'http://127.0.0.1:8848', | ||
changeOrigin: true, | ||
rewrite: (path) => path.replace(/^\/mock/, ''), | ||
}, | ||
}; | ||
|
||
export default mergeConfig(baseConfig, { | ||
server: { | ||
proxy: { | ||
...proxyConfig, | ||
}, | ||
}, | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/toolkits/pro/template/tinyvue2/config/vite.config.prod.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { mergeConfig } from 'vite'; | ||
import baseConfig from './vite.config.base'; | ||
|
||
export default mergeConfig( | ||
{ | ||
build: { | ||
rollupConfig: { | ||
output: { | ||
manualChunks: { | ||
vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'], | ||
}, | ||
}, | ||
}, | ||
chunkSizeWarningLimit: 2000, | ||
}, | ||
}, | ||
baseConfig | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
packages/toolkits/pro/template/tinyvue2/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
const { resolve } = require('path'); | ||
const { VueLoaderPlugin } = require('vue-loader'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const rspack = require('@rspack/core'); | ||
const { configDotenv, parse } = require('dotenv'); | ||
const { default: importMetaLoader } = require('import-meta-loader'); | ||
const path = require('path'); | ||
configDotenv({ | ||
path: './.env', | ||
}); | ||
|
||
/** @type {import('@rspack/cli').Configuration} */ | ||
const config = { | ||
context: __dirname, | ||
entry: { | ||
main: './src/main.ts', | ||
}, | ||
output: { | ||
path: resolve(__dirname, 'dist'), // 打包后的文件输出的目录 | ||
filename: `js/[name]_[chunkhash:8].js`, // 设置打包后的 js 文件名,如果在文件名前增加文件路径,会将打包后的 js 文件放在指定的文件夹下 | ||
publicPath: '/', | ||
}, | ||
experiments: { | ||
css: true, | ||
}, | ||
plugins: [ | ||
new VueLoaderPlugin(), | ||
new rspack.HtmlRspackPlugin({ | ||
template: './index.html', | ||
}), | ||
new rspack.DefinePlugin({ | ||
__VUE_OPTIONS_API__: JSON.stringify(true), | ||
__VUE_PROD_DEVTOOLS__: JSON.stringify(false), | ||
'import.meta.env.VITE_CONTEXT': '"/vue-pro/"', | ||
'import.meta.env.VITE_BASE_API': '"/api"', | ||
'import.meta.env.VITE_SERVER_HOST': '"http://127.0.0.1:3000"', | ||
'import.meta.env.VITE_MOCK_HOST': '"http://127.0.0.1:8848"', | ||
'import.meta.env.VITE_USE_MOCK': 'false', | ||
'import.meta.env.VITE_MOCK_IGNORE': | ||
'"/api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee"', | ||
'import.meta.env.VITE_MOCK_SERVER_HOST': '"/mock"', | ||
BUILD_TOOLS: "'RSPACK'", | ||
}), | ||
], | ||
devServer: { | ||
historyApiFallback: true, | ||
proxy: [ | ||
{ | ||
context: [process.env.VITE_BASE_API], | ||
target: process.env.VITE_SERVER_HOST, | ||
changeOrigin: true, | ||
pathRewrite: { | ||
'^/api': '', | ||
}, | ||
}, | ||
{ | ||
context: [process.env.VITE_MOCK_SERVER_HOST], | ||
target: process.env.VITE_MOCK_HOST, | ||
changeOrigin: true, | ||
pathRewrite: { | ||
'^/mock': '', | ||
}, | ||
}, | ||
], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.vue$/, | ||
loader: 'vue-loader', | ||
options: { | ||
experimentalInlineMatchResource: true, | ||
}, | ||
}, | ||
{ | ||
test: /\.ts$/, | ||
loader: 'builtin:swc-loader', | ||
options: { | ||
sourceMap: true, | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
}, | ||
}, | ||
}, | ||
type: 'javascript/auto', | ||
}, | ||
{ | ||
test: /\.less$/, | ||
loader: 'less-loader', | ||
type: 'css', | ||
}, | ||
{ | ||
test: /\.svg$/, | ||
type: 'asset/resource', | ||
}, | ||
{ | ||
test: /\.m?js/, | ||
resolve: { | ||
fullySpecified: false, | ||
}, | ||
}, | ||
{ | ||
test: /\.less$/, | ||
use: [ | ||
{ | ||
loader: 'less-loader', | ||
options: { | ||
additionalData: `@import "${resolve( | ||
'./src/assets/style/breakpoint.less' | ||
)}";`, | ||
}, | ||
}, | ||
], | ||
type: 'css', | ||
}, | ||
{ | ||
test: /.(png|jpg|jpeg|gif|svg)$/, // 匹配图片文件 | ||
type: 'asset', // type选择asset | ||
parser: { | ||
dataUrlCondition: { | ||
maxSize: 10 * 1024, // 小于10kb转base64位 | ||
}, | ||
}, | ||
generator: { | ||
filename: 'static/images/[name].[contenthash:8][ext]', // 文件输出目录和命名 | ||
}, | ||
}, | ||
{ | ||
test: /.(woff2?|eot|ttf|otf)$/, // 匹配字体图标文件 | ||
type: 'asset', // type选择asset | ||
parser: { | ||
dataUrlCondition: { | ||
maxSize: 10 * 1024, // 小于10kb转base64位 | ||
}, | ||
}, | ||
generator: { | ||
filename: 'static/fonts/[name].[contenthash:8][ext]', // 文件输出目录和命名 | ||
}, | ||
}, | ||
{ | ||
test: /.(mp4|webm|ogg|mp3|wav|flac|aac)$/, // 匹配媒体文件 | ||
type: 'asset', // type选择asset | ||
parser: { | ||
dataUrlCondition: { | ||
maxSize: 10 * 1024, // 小于10kb转base64位 | ||
}, | ||
}, | ||
generator: { | ||
filename: 'static/media/[name].[contenthash:8][ext]', // 文件输出目录和命名 | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
alias: { | ||
'@': resolve(__dirname, 'src'), | ||
assets: resolve(__dirname, 'src/assets'), | ||
}, | ||
extensions: ['.ts', '.js', '.vue'], | ||
}, | ||
}; | ||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
packages/toolkits/pro/template/tinyvue2/src/router/routes/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.