vite.config.js
注释版本
import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
base: "./",
publicDir: "public",
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
css: {
preprocessorOptions: {
scss: {
charset: false,
javascriptEnabled: true,
additionalData: `@import "${path.resolve(
__dirname,
"src/assets/css/var.scss"
)}";`,
},
},
},
json: {
namedExports: true,
stringify: false,
},
esbuild: {
jsxFactory: "h",
jsxFragment: "Fragment",
jsxInject: `import Vue from 'vue'`,
},
build: {
target: "modules",
outDir: "dist",
assetsDir: "assets",
assetsInlineLimit: "4096",
cssCodeSplit: true,
sourcemap: false,
minify: "terser",
write: true,
emptyOutDir: true,
brotliSize: true,
chunkSizeWarningLimit: 500,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
server: {
host: "127.0.0.1",
port: 5173,
open: "/publick/index.html",
strictPort: false,
https: false,
cors: true,
header: {},
hmr: {},
watch: {},
middlewareMode: "ssr",
base: "",
fs: {
strict: true,
allow: [
searchForWorkspaceRoot(process.cwd()),
"/path/to/custom/allow",
],
deny: [".env", ".env.*", "*.{pem,crt}"],
},
origin: "http://127.0.0.1:8080",
proxy: {
"/foo": "http://127.0.0.1:4567",
"/api": {
target: "http://127.0.0.1:4567",
changeOrigin: true,
rewrite: (path) => {
path = path.replace(/^\/api/, "");
console.log('vite proxy url: ',path);
return path;
},
},
"^/*.*m3u8*": {
target: "http://127.0.0.1:4567",
changeOrigin: true,
secure: false,
rewrite: (path) => path,
},
"/api": {
target: "http://jsonplaceholder.typicode.com",
changeOrigin: true,
configure: (proxy, options) => {
},
},
"/socket.io": {
target: "ws://localhost:3000",
ws: true,
},
},
},
preview: {
host: "localhost",
port: "5173",
strictPort: true,
https: "",
open: "/docs/index.html",
cors: {},
proxy: {
"/foo": "http://localhost:4567",
"/api": {
target: "http://jsonplaceholder.typicode.com",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
optimizeDeps: {
entries: [],
exclude: ["jquery"],
include: [],
esbuildOptions: {},
force: true,
disabled: 'build',
},
ssr: {
external: [],
noExternal: [],
target: "node",
format: "esm",
},
worker: {
format: "iife",
plugins: [],
rollupOptions: {},
},
});
无注释版本
import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
base: "./",
publicDir: "public",
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
css: {
preprocessorOptions: {
scss: {
charset: false,
javascriptEnabled: true,
additionalData: `@import "${path.resolve(
__dirname,
"src/assets/css/var.scss"
)}";`,
},
},
},
json: {
namedExports: true,
stringify: false,
},
esbuild: {
jsxFactory: "h",
jsxFragment: "Fragment",
jsxInject: `import Vue from 'vue'`,
},
build: {
target: "modules",
outDir: "dist",
assetsDir: "assets",
assetsInlineLimit: "4096",
cssCodeSplit: true,
sourcemap: false,
minify: "terser",
write: true,
emptyOutDir: true,
brotliSize: true,
chunkSizeWarningLimit: 500,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
server: {
host: "127.0.0.1",
port: 5173,
open: "/publick/index.html",
strictPort: false,
https: false,
cors: true,
header: {},
hmr: {},
watch: {},
middlewareMode: "ssr",
base: "",
fs: {
strict: true,
allow: [searchForWorkspaceRoot(process.cwd()), "/path/to/custom/allow"],
deny: [".env", ".env.*", "*.{pem,crt}"],
},
origin: "http://127.0.0.1:8080",
proxy: {
"/foo": "http://127.0.0.1:4567",
"/api": {
target: "http://j127.0.0.1:4567",
changeOrigin: true,
rewrite: (path) => {
path.replace(/^\/api/, "");
console.log(path);
return path;
},
},
"^/*.*m3u8*": {
target: "http://127.0.0.1:4567",
changeOrigin: true,
secure: false,
rewrite: (path) => path,
},
"/api": {
target: "http://jsonplaceholder.typicode.com",
changeOrigin: true,
configure: (proxy, options) => {},
},
"/socket.io": {
target: "ws://localhost:3000",
ws: true,
},
},
},
preview: {
host: "localhost",
port: "5173",
strictPort: true,
https: "",
open: "/docs/index.html",
cors: {},
proxy: {
"/foo": "http://localhost:4567",
"/api": {
target: "http://jsonplaceholder.typicode.com",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
optimizeDeps: {
entries: [],
exclude: ["jquery"],
include: [],
esbuildOptions: {},
force: true,
disabled: "build",
},
ssr: {
external: [],
noExternal: [],
target: "node",
format: "esm",
},
worker: {
format: "iife",
plugins: [],
rollupOptions: {},
},
});
webpack.config.js
const path = require("path");
const ESLintWebpackPlugin = require("eslint-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./src/main.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "static/js/main.js",
clean: true,
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.less$/,
use: ["style-loader", "css-loader", "less-loader"],
},
{
test: /\.s[ac]ss$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.styl$/,
use: ["style-loader", "css-loader", "stylus-loader"],
},
{
test: /\.(png|jpe?g|gif|webp)$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
},
generator: {
filename: "static/imgs/[hash:8][ext][query]",
},
},
{
test: /\.(ttf|woff2?)$/,
type: "asset/resource",
generator: {
filename: "static/media/[hash:8][ext][query]",
},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
],
},
plugins: [
new ESLintWebpackPlugin({
context: path.resolve(__dirname, "src"),
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "public/index.html"),
}),
],
devServer: {
host: "localhost",
port: "3000",
open: true,
proxy: {
'/api': {
target: 'http://localhost:4000',
changeOrigin: true,
pathRewrite: function (path, req) {
const newPath = path.replace('/api', '/base/api')
console.log(newPath)
return newPath
}
},
},
mode: "development",
};
babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['last 2 versions', 'ie >= 11']
},
useBuiltIns: 'usage',
corejs: 3.8
}
]
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties'
]
};
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": ["element-plus/global"],
"paths": {
"@/*": ["./src/*"],
"components/*": ["./src/components/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": [
"./src/**/*.vue"
],
"exclude": ["./node_modules"]
}
.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/typescript/recommended',
'@vue/prettier',
'@vue/prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
parserOptions: {
ecmaVersion: 2020
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off'
}
}
.prettierrc
注释版
{
"singleQuote": true, // 是否使用单引号,默认为 false
"semi": true, // 是否在语句末尾添加分号,默认为 true
"trailingComma": "all", // 否在对象或数组的最后一个元素后面添加逗号,默认为 none。可选值:none、es5、all
"printWidth": 120, // 一行代码的最大宽度,默认为 80
"tabWidth": 2, // 缩进的空格数,默认为 2
"useTabs": false, // 是否使用制表符作为缩进,默认为 false
"bracketSpacing": true, // 对象字面量的括号之间是否添加空格,默认为 true
"jsxBracketSameLine": false, // 多行 JSX 元素的最后一行的右尖括号是否放在最后一行的结尾,默认为 false
"arrowParens": "avoid", // 只有一个参数的箭头函数的参数是否使用圆括号,默认为 avoid。可选值:avoid、always
"rangeStart": 0, // 指定格式化的代码范围开始行,默认为 0
"rangeEnd": null, // 指定格式化的代码范围结束行,可以不写 默认为 Infinity(或null)
"requirePragma": false, // 是否只格式化带有特定注释的文件,默认为 false
"insertPragma": false, // 是否在文件开头插入特定的注释,默认为 false
"proseWrap": "preserve", // 如何处理 prose(文本块),默认为 preserve。可选值:always、never、preserve
"htmlWhitespaceSensitivity": "css", // 如何处理 HTML 文件中的空格,默认为 css。可选值:css、strict、ignore
"vueIndentScriptAndStyle": false, // Vue 文件中是否对 `<script>` 和 `<style>` 标签进行缩进,默认为 false
"endOfLine": "auto" // 换行符的样式,默认为 auto。可选值:auto、lf、crlf
}
无注释版
{
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"rangeStart": 0,
"rangeEnd": null,
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "auto"
}
package.json
{
"name": "项目名称",
"version": "1.0.0",
"description": "项目描述",
"main": "index.js",
"keywords": ["关键字1", "关键字2", "关键字3"],
"repository": {
"type": "git",
"url": "https://example.com/project.git"
},
"license": "MIT",
"author": "作者名称",
"contributors": [
{ "name": "贡献者1", "email": "贡献者1邮箱" },
{ "name": "贡献者2", "email": "贡献者2邮箱" }
],
"dependencies": {
"模块1": "^1.0.0",
"模块2": "~2.0.0"
},
"devDependencies": {
"模块3": "^3.0.0",
"模块4": "~4.0.0"
},
"scripts": {
"start": "node index.js",
"test": "mocha test.js"
},
"engines": {
"node": ">=12.0.0"
}
}
.gitignore
/node_modules
/.pnp
.pnp.js
/package-lock.json
/coverage
/.next/
/out/
/build
.DS_Store
*.pem
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env*.local
.vercel
*.tsbuildinfo
next-env.d.ts
jsconfig.json
- 用来解决在vscode中webpack,vite,vue,react项目中alias别名
@
路径不能跳转的问题
- 项目根目录下添加
jsconfig.json
文件,添加后重启vscode
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"target": "ES6",
"allowSyntheticDefaultImports": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}