fix: vite plugin cause source map error (#108)

* fix: fix source map error

* fix: import way of @mui

* fix: istanbul only when test is true
This commit is contained in:
lumix
2025-05-12 10:05:20 +08:00
committed by GitHub
parent 9aef5fec0c
commit c24c887ac6
11 changed files with 43 additions and 30 deletions

View File

@@ -9,6 +9,7 @@ on:
env: env:
NODE_VERSION: "18.16.0" NODE_VERSION: "18.16.0"
PNPM_VERSION: "8.5.0" PNPM_VERSION: "8.5.0"
COVERAGE: "true"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true cancel-in-progress: true
@@ -45,10 +46,14 @@ jobs:
build: pnpm run build build: pnpm run build
start: pnpm run start start: pnpm run start
browser: chrome browser: chrome
env:
COVERAGE: "true"
- name: Jest run - name: Jest run
run: | run: |
pnpm run test:unit pnpm run test:unit
env:
COVERAGE: "true"
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: codecov/codecov-action@v2 uses: codecov/codecov-action@v2

View File

@@ -5,6 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"dev:coverage": "cross-env COVERAGE=true vite",
"build": "vite build", "build": "vite build",
"lint": "tsc --noEmit --project tsconfig.web.json && eslint --ext .js,.ts,.tsx . --ignore-path .eslintignore.web", "lint": "tsc --noEmit --project tsconfig.web.json && eslint --ext .js,.ts,.tsx . --ignore-path .eslintignore.web",
"start": "vite preview --port 3000", "start": "vite preview --port 3000",
@@ -14,8 +15,10 @@
"test": "pnpm run test:unit && pnpm run test:components", "test": "pnpm run test:unit && pnpm run test:components",
"test:components": "cypress run --component --browser chrome --headless", "test:components": "cypress run --component --browser chrome --headless",
"test:unit": "jest --coverage", "test:unit": "jest --coverage",
"test:unit:coverage": "cross-env COVERAGE=true jest --coverage",
"test:components:coverage": "cross-env COVERAGE=true cypress run --component --browser chrome --headless",
"test:cy": "cypress run", "test:cy": "cypress run",
"coverage": "pnpm run test:unit && pnpm run test:components", "coverage": "cross-env COVERAGE=true pnpm run test:unit && cross-env COVERAGE=true pnpm run test:components",
"generate-tokens": "node scripts/system-token/convert-tokens.cjs" "generate-tokens": "node scripts/system-token/convert-tokens.cjs"
}, },
"dependencies": { "dependencies": {

View File

@@ -5,7 +5,7 @@ import React, { useCallback, useRef, useMemo } from 'react';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { TitleOutlined } from '@mui/icons-material'; import TitleOutlined from '@mui/icons-material/TitleOutlined';
export interface ColorPickerProps { export interface ColorPickerProps {
onChange?: (format: EditorMarkFormat.FontColor | EditorMarkFormat.BgColor, color: string) => void; onChange?: (format: EditorMarkFormat.FontColor | EditorMarkFormat.BgColor, color: string) => void;

View File

@@ -1,5 +1,8 @@
import { notify } from '@/components/_shared/notify'; import { notify } from '@/components/_shared/notify';
import { TaskAltRounded } from '@mui/icons-material';
import TaskAltRounded from '@mui/icons-material/TaskAltRounded';
import DeleteIcon from '@mui/icons-material/Delete';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { import {
Box, Box,
@@ -11,7 +14,6 @@ import {
ListItemText, ListItemText,
Typography, Typography,
} from '@mui/material'; } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
const MAX_DELETE = 50; const MAX_DELETE = 50;
const IndexedDBCleaner = () => { const IndexedDBCleaner = () => {

View File

@@ -2,6 +2,7 @@ import FileDropzone from '@/components/_shared/file-dropzone/FileDropzone';
import { notify } from '@/components/_shared/notify'; import { notify } from '@/components/_shared/notify';
import { TabPanel, ViewTab, ViewTabs } from '@/components/_shared/tabs/ViewTabs'; import { TabPanel, ViewTab, ViewTabs } from '@/components/_shared/tabs/ViewTabs';
import { AFConfigContext } from '@/components/main/app.hooks'; import { AFConfigContext } from '@/components/main/app.hooks';
import LinearProgress from '@mui/material/LinearProgress'; import LinearProgress from '@mui/material/LinearProgress';
import React, { useCallback, useContext } from 'react'; import React, { useCallback, useContext } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';

View File

@@ -1,10 +1,8 @@
import { import ErrorOutline from '@mui/icons-material/ErrorOutline';
ErrorOutline, import HighlightOff from '@mui/icons-material/HighlightOff';
HighlightOff, import PowerSettingsNew from '@mui/icons-material/PowerSettingsNew';
PowerSettingsNew, import TaskAltRounded from '@mui/icons-material/TaskAltRounded';
TaskAltRounded, import IconButton from '@mui/material/IconButton';
} from '@mui/icons-material';
import { IconButton } from '@mui/material';
import React from 'react'; import React from 'react';
import { useSnackbar, SnackbarContent, CustomContentProps } from 'notistack'; import { useSnackbar, SnackbarContent, CustomContentProps } from 'notistack';
import { ReactComponent as CloseIcon } from '@/assets/icons/close.svg'; import { ReactComponent as CloseIcon } from '@/assets/icons/close.svg';

View File

@@ -2,8 +2,11 @@ import { NormalModal } from '@/components/_shared/modal';
import { notify } from '@/components/_shared/notify'; import { notify } from '@/components/_shared/notify';
import { useAppViewId, useCurrentWorkspaceId } from '@/components/app/app.hooks'; import { useAppViewId, useCurrentWorkspaceId } from '@/components/app/app.hooks';
import { AFConfigContext, useCurrentUser, useService } from '@/components/main/app.hooks'; import { AFConfigContext, useCurrentUser, useService } from '@/components/main/app.hooks';
import { TaskAltRounded } from '@mui/icons-material';
import { Button, Divider, Typography } from '@mui/material'; import TaskAltRounded from '@mui/icons-material/TaskAltRounded';
import Button from '@mui/material/Button';
import Divider from '@mui/material/Divider';
import Typography from '@mui/material/Typography';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { useTranslation, Trans } from 'react-i18next'; import { useTranslation, Trans } from 'react-i18next';
import { ReactComponent as AppflowyLogo } from '@/assets/icons/appflowy.svg'; import { ReactComponent as AppflowyLogo } from '@/assets/icons/appflowy.svg';

View File

@@ -5,7 +5,8 @@ import AppTheme from '@/components/main/AppTheme';
import AppConfig from '@/components/main/AppConfig'; import AppConfig from '@/components/main/AppConfig';
import { Suspense } from 'react'; import { Suspense } from 'react';
import { SnackbarProvider } from 'notistack'; import { SnackbarProvider } from 'notistack';
import { styled } from '@mui/material';
import { styled } from '@mui/material/styles';
import { InfoSnackbar } from '../_shared/notify'; import { InfoSnackbar } from '../_shared/notify';
const StyledSnackbarProvider = styled(SnackbarProvider)` const StyledSnackbarProvider = styled(SnackbarProvider)`

View File

@@ -4,7 +4,7 @@ import ChangeAccount from '@/components/_shared/modal/ChangeAccount';
import { notify } from '@/components/_shared/notify'; import { notify } from '@/components/_shared/notify';
import { getAvatar } from '@/components/_shared/view-icon/utils'; import { getAvatar } from '@/components/_shared/view-icon/utils';
import { AFConfigContext, useCurrentUser, useService } from '@/components/main/app.hooks'; import { AFConfigContext, useCurrentUser, useService } from '@/components/main/app.hooks';
import { EmailOutlined } from '@mui/icons-material'; import EmailOutlined from '@mui/icons-material/EmailOutlined';
import { Avatar, Button, Divider } from '@mui/material'; import { Avatar, Button, Divider } from '@mui/material';
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react'; import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';

View File

@@ -1,5 +1,6 @@
import Import from '@/components/_shared/more-actions/importer/Import'; import Import from '@/components/_shared/more-actions/importer/Import';
import { Typography } from '@mui/material';
import Typography from '@mui/material/Typography';
import React from 'react'; import React from 'react';
import { ReactComponent as AppflowyLogo } from '@/assets/icons/appflowy.svg'; import { ReactComponent as AppflowyLogo } from '@/assets/icons/appflowy.svg';
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from 'react-router-dom';

View File

@@ -1,8 +1,7 @@
import { defineConfig } from 'vite'; import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr'; import svgr from 'vite-plugin-svgr';
import { visualizer } from 'rollup-plugin-visualizer'; import { visualizer } from 'rollup-plugin-visualizer';
import usePluginImport from 'vite-plugin-importer';
import { totalBundleSize } from 'vite-plugin-total-bundle-size'; import { totalBundleSize } from 'vite-plugin-total-bundle-size';
import path from 'path'; import path from 'path';
import istanbul from 'vite-plugin-istanbul'; import istanbul from 'vite-plugin-istanbul';
@@ -12,6 +11,7 @@ import { viteExternalsPlugin } from 'vite-plugin-externals';
const resourcesPath = path.resolve(__dirname, '../resources'); const resourcesPath = path.resolve(__dirname, '../resources');
const isDev = process.env.NODE_ENV === 'development'; const isDev = process.env.NODE_ENV === 'development';
const isProd = process.env.NODE_ENV === 'production'; const isProd = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test' || process.env.COVERAGE === 'true';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
@@ -34,7 +34,6 @@ export default defineConfig({
isProd ? viteExternalsPlugin({ isProd ? viteExternalsPlugin({
react: 'React', react: 'React',
'react-dom': 'ReactDOM', 'react-dom': 'ReactDOM',
}) : undefined, }) : undefined,
svgr({ svgr({
svgrOptions: { svgrOptions: {
@@ -72,7 +71,8 @@ export default defineConfig({
}, },
}, },
}), }),
istanbul({ // Enable istanbul for code coverage (active if isTest is true)
isTest ? istanbul({
cypress: true, cypress: true,
requireEnv: false, requireEnv: false,
include: ['src/**/*'], include: ['src/**/*'],
@@ -81,13 +81,7 @@ export default defineConfig({
'cypress/**/*', 'cypress/**/*',
'node_modules/**/*', 'node_modules/**/*',
], ],
}), }) : undefined,
usePluginImport({
libraryName: '@mui/icons-material',
libraryDirectory: '',
camel2DashComponentName: false,
style: false,
}),
process.env.ANALYZE_MODE process.env.ANALYZE_MODE
? visualizer({ ? visualizer({
emitFile: true, emitFile: true,
@@ -109,15 +103,20 @@ export default defineConfig({
ignored: ['node_modules'], ignored: ['node_modules'],
}, },
cors: false, cors: false,
sourcemapIgnoreList: false,
}, },
envPrefix: ['AF'], envPrefix: ['AF'],
esbuild: { esbuild: {
keepNames: true,
sourcesContent: true,
sourcemap: true,
minifyIdentifiers: false, // Disable identifier minification in development
minifySyntax: false, // Disable syntax minification in development
pure: !isDev ? ['console.log', 'console.debug', 'console.info', 'console.trace'] : [], pure: !isDev ? ['console.log', 'console.debug', 'console.info', 'console.trace'] : [],
}, },
build: { build: {
target: `esnext`, target: `esnext`,
reportCompressedSize: true, reportCompressedSize: true,
sourcemap: isDev,
rollupOptions: isProd rollupOptions: isProd
? { ? {