Skip to content

Commit

Permalink
refactor: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Apr 17, 2022
1 parent d065ec4 commit b7f9715
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"sideEffects": false,
"scripts": {
"preinstall": "npx only-allow pnpm",
"play": "pnpm run --filter ./playground dev",
"dev": "pnpm run dev --parallel",
"build": "pnpm run build --filter '*'",
"lint": "eslint --fix .",
Expand Down
10 changes: 9 additions & 1 deletion packages/create-ant-design-pro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"version": "0.0.3",
"packageManager": "pnpm@6.32.3",
"description": "",
"keywords": [],
"keywords": [
"create",
"ant-design-pro",
"vite",
"antd",
"antd admin",
"vite antd",
"vite antd admin"
],
"homepage": "https://vite-ant-design-pro.vercel.app",
"bugs": {
"url": "https://github.com/1247748612/vite-ant-design-pro/issues"
Expand Down
14 changes: 11 additions & 3 deletions packages/create-ant-design-pro/template-react-ts/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import * as path from 'path'

export default defineConfig({
resolve: {
alias: {
'@': path.join(__dirname, 'src'),
},
alias: [
{
find: /^~/,
replacement: '',
},
{
find: '@',
replacement: path.resolve(__dirname, 'src'),
},
],
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: '@root-entry-name: default;',
},
},
Expand Down
36 changes: 8 additions & 28 deletions packages/vite-plugin-antd-layout/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,8 @@ export default function antdLayout(): Plugin {
name: 'vite-plugin-antd-layout',
enforce: 'pre',
config: () => ({
build: {
dynamicImportVarsOptions: {
exclude: [],
},
},
resolve: {
alias: [
{
find: /^~/,
replacement: '',
},
],
dedupe: ['antd', '@ant-design/pro-layout'],
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
dedupe: ['vite-plugin-antd-layout'],
},
}),
configResolved(_config) {
Expand All @@ -49,7 +31,7 @@ export default function antdLayout(): Plugin {
modulePath = (await this.resolve(name))?.id
modulePath = modulePath ?? require.resolve(name).replace(/\..+/, '')

const code = `export { default } from "${modulePath}";`
const code = `export { default } from ${JSON.stringify(modulePath)};`
return { code, map: new MagicString(code).generateMap() }
}
},
Expand All @@ -61,16 +43,14 @@ export default function antdLayout(): Plugin {
path.join(path.relative(dirname(id), config.root), 'src/pages')
)

const replaceCode = 'ComponentKeys = Object.keys(ComponentMemo);'
const index = code.indexOf(replaceCode)
const index = code.indexOf(
'ComponentKeys = Object.keys(ComponentMemo);'
)

ms.overwrite(
ms.prependLeft(
index,
index + replaceCode.length,
`
// automatically generated by vite-plugin-antd-layout
ComponentMemo = import.meta.glob('${globPath}/**/*.tsx');
${replaceCode}
`// automatically generated by vite-plugin-antd-layout
ComponentMemo = import.meta.glob('${globPath}/**/*.tsx');
`
)

Expand Down
17 changes: 12 additions & 5 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import antdLayout from 'vite-plugin-antd-layout'
import momentToDayjs from 'unplugin-moment-to-dayjs/vite'
import * as path from 'path'

export default defineConfig({
resolve: {
alias: {
'@': path.join(__dirname, 'src'),
},
alias: [
{
find: /^~/,
replacement: '',
},
{
find: '@',
replacement: path.resolve(__dirname, 'src'),
},
],
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: '@root-entry-name: default;',
},
},
Expand All @@ -30,5 +37,5 @@ export default defineConfig({
},
},
},
plugins: [react(), antdLayout(), momentToDayjs()],
plugins: [react(), antdLayout()],
})

1 comment on commit b7f9715

@vercel
Copy link

@vercel vercel bot commented on b7f9715 Apr 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.