Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增rspack构建工具 #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/toolkits/pro/template/tinyvue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build": "vite build --config ./config/vite.config.prod.ts",
"build:wp": "webpack --config webpack.config.js",
"dev:wp": "webpack-dev-server --progress --config webpack.config.js",
"dev:rp": "rspack serve",
"build:rp": "rspack build",
"report": "cross-env REPORT=true npm run build",
"lint-staged": "npx lint-staged",
"prepare": "git init && husky install",
Expand Down Expand Up @@ -56,13 +58,16 @@
"vue": "^3.3.7",
"vue-eslint-parser": "^9.3.2",
"vue-i18n": "^9.6.2",
"vue-router": "^4.2.5"
"vue-router": "^4.2.5",
"vue-style-loader": "^4.1.3"
},
"devDependencies": {
"@babel/preset-env": "^7.25.3",
"@babel/preset-typescript": "^7.24.7",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^12.0.1",
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@types/lodash": "^4.14.177",
"@types/nprogress": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
Expand Down
155 changes: 155 additions & 0 deletions packages/toolkits/pro/template/tinyvue/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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');
configDotenv({
path:'./.env'
})

/** @type {import('@rspack/cli').Configuration} */
const config = {
context: __dirname,
entry: {
main: './src/main.ts',
},
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"',
})
],
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'),
'vue-i18n$': 'vue-i18n/dist/vue-i18n.esm-bundler.js',
'vue$': 'vue/dist/vue.esm-bundler.js'
},
extensions: ['.ts', '.js', '.vue'],
},
}
module.exports = config;
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export interface ITreeNodeData {
// 国际化
locale: string;
}

const views = import.meta.glob('../../views/**/*.vue');

const reg = /\.vue$/gim;
const views = import.meta.glob ? import.meta.glob('../../views/**/*.vue') : require.context('../../views', true, reg, 'sync');
console.log(views)
const toRoutes = (menus: ITreeNodeData[]) => {
const router: RouteRecordRaw[] = [];
for (let i=0;i<menus.length;i+=1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RouteRecordRaw } from 'vue-router';

const modules = import.meta.glob('./modules/*.ts', { eager: true });
const modules = import.meta.glob ? import.meta.glob('./modules/*.ts', { eager: true }) : require.context('./module', false, /\.ts$/, 'sync')
const appRoutes: RouteRecordRaw[] = [];

Object.keys(modules).forEach((key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
const userStore = useUserStore();
const loginFormMail = ref();

const views = import.meta.glob('../../**/*.vue');

const rules = computed(() => {
return {
mailname: [
Expand Down
1 change: 0 additions & 1 deletion packages/toolkits/pro/template/tinyvue/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ module.exports = {
'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"',

})
],
resolve: {
Expand Down