-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add vite-plugin-html. Delete updateHtml related logic
- Loading branch information
Showing
19 changed files
with
224 additions
and
286 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
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
build/plugin/gzip/compress.ts → build/vite/plugin/gzip/compress.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
File renamed without changes.
File renamed without changes.
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,76 @@ | ||
import type { Plugin as VitePlugin } from 'vite'; | ||
import type { Plugin as rollupPlugin } from 'rollup'; | ||
|
||
import { createMockServer } from 'vite-plugin-mock'; | ||
import ViteHtmlPlugin from 'vite-plugin-html'; | ||
import PurgeIcons from 'vite-plugin-purge-icons'; | ||
|
||
import visualizer from 'rollup-plugin-visualizer'; | ||
import gzipPlugin from './gzip/index'; | ||
|
||
import { hmScript } from '../hm'; | ||
|
||
const pkg = require('../../../package.json'); | ||
|
||
import { isDevFn, isProdFn, isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils'; | ||
import { GLOB_CONFIG_FILE_NAME } from '../../constant'; | ||
|
||
// gen vite plugins | ||
export function createVitePlugins(viteEnv: ViteEnv) { | ||
const { VITE_USE_MOCK, VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv; | ||
|
||
const vitePlugins: VitePlugin[] = []; | ||
|
||
// vite-plugin-html | ||
vitePlugins.push( | ||
ViteHtmlPlugin({ | ||
// html title | ||
title: VITE_GLOB_APP_TITLE, | ||
minify: isProdFn(), | ||
options: { | ||
// Package and insert additional configuration files | ||
injectConfig: isProdFn() | ||
? `<script src='${VITE_PUBLIC_PATH || './'}${GLOB_CONFIG_FILE_NAME}?v=${ | ||
pkg.version | ||
}-${new Date().getTime()}'></script>` | ||
: '', | ||
// Insert Baidu statistics code | ||
hmScript: isSiteMode() ? hmScript : '', | ||
}, | ||
}) | ||
); | ||
|
||
// vite-plugin-purge-icons | ||
vitePlugins.push(PurgeIcons()); | ||
|
||
// vite-plugin-mock | ||
if (isDevFn() && VITE_USE_MOCK) { | ||
// open mock | ||
vitePlugins.push( | ||
createMockServer({ | ||
ignore: /^\_/, | ||
mockPath: 'mock', | ||
}) | ||
); | ||
} | ||
return vitePlugins; | ||
} | ||
|
||
// gen rollup plugins | ||
export function createRollupPlugin() { | ||
const rollupPlugins: rollupPlugin[] = []; | ||
|
||
if (isProdFn()) { | ||
if (isReportMode()) { | ||
// rollup-plugin-visualizer | ||
rollupPlugins.push( | ||
visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin | ||
); | ||
} | ||
if (isBuildGzip() || isSiteMode()) { | ||
// rollup-plugin-gizp | ||
rollupPlugins.push(gzipPlugin()); | ||
} | ||
} | ||
return rollupPlugins; | ||
} |
File renamed without changes.
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
Oops, something went wrong.