Skip to content

Commit df6ab6f

Browse files
committed
feat: add vite-plugin-html-template
1 parent 2c700c8 commit df6ab6f

File tree

11 files changed

+28
-177
lines changed

11 files changed

+28
-177
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<a name="1.0.0-rc.0"></a>
2+
# [1.0.0-rc.0](https://github.com/IndexXuan/vue-cli-plugin-vite/compare/v0.4.4...v1.0.0-rc.0) (2021-04-07)
3+
4+
5+
### Features
6+
7+
* add vite-plugin-html-template ([b7f0917](https://github.com/IndexXuan/vue-cli-plugin-vite/commit/b7f0917))
8+
9+
10+
11+
<a name="0.4.4"></a>
12+
## [0.4.4](https://github.com/IndexXuan/vue-cli-plugin-vite/compare/v0.4.3...v0.4.4) (2021-04-06)
13+
14+
15+
116
<a name="0.4.4"></a>
217
## [0.4.4](https://github.com/IndexXuan/vue-cli-plugin-vite/compare/v0.4.3...v0.4.4) (2021-04-06)
318

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ vue add vite
7575
# NOTE you cannot directly use `vite` or `npx vite` since it is origin vite not this plugin.
7676
yarn vite // or npm run vite
7777
```
78-
the plugin\'s generator will write some `main.html` for corresponding main.{js,ts}, since vite need html file for dev-server entry file
7978

8079

8180
## Motivation
@@ -127,12 +126,10 @@ the plugin\'s generator will write some `main.html` for corresponding main.{js,t
127126

128127
### Compatibility
129128
- **NO EXTRA** files, code and dependencies injected
130-
- injected corresponding main.html
131-
- SPA: `projectRoot/main.html`
132-
- MPA: `projectRoot/src/pages/*/main.html`(s)
133129
- injected one devDependency `vue-cli-plugin-vite`
134130
- injected one line code in `package.json#scripts#vite` and one file at `bin/vite`
135131
- auto-resolved as much options as we can from `vue.config.js` (publicPath, alias, outputDir...)
132+
- auto reuse public/index.html as vite html entry template
136133
- compatible the differences between vue-cli and vite(environment variables, special syntax...)
137134

138135

@@ -255,6 +252,7 @@ $--font-path: '~element-plus/lib/theme-chalk/fonts'; // changed to 'path/to/node
255252
## Relevant Vite Plugins
256253
- [vite-plugin-vue2@underfin](https://github.com/underfin/vite-plugin-vue2)
257254
- [vite-plugin-env-compatible](https://github.com/IndexXuan/vite-plugin-env-compatible)
255+
- [vite-plugin-html-template](https://github.com/IndexXuan/vite-plugin-html-template)
258256
- [vite-plugin-vue-cli](https://github.com/IndexXuan/vite-plugin-vue-cli)
259257
- [vite-plugin-mpa](https://github.com/IndexXuan/vite-plugin-mpa)
260258

config/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { defineConfig } from 'vite'
22
import { createVuePlugin } from 'vite-plugin-vue2'
33
import envCompatible from 'vite-plugin-env-compatible'
4+
import htmlTemplate from 'vite-plugin-html-template'
45
import vueCli, { VueCliOptions } from 'vite-plugin-vue-cli'
56
import mpa from 'vite-plugin-mpa'
67
import path from 'path'
8+
import chalk from 'chalk'
79
import { Options } from './options'
810
import { name } from '../package.json'
911

@@ -14,6 +16,7 @@ let vueConfig: VueCliOptions = {}
1416
try {
1517
vueConfig = require(resolve('vue.config.js')) || {}
1618
} catch (e) {
19+
console.error(chalk.redBright(e))
1720
/**/
1821
}
1922

@@ -23,7 +26,7 @@ const extraPlugins = viteOptions.plugins || []
2326

2427
if (viteOptions.alias) {
2528
console.log(
26-
`[${name}]: pluginOptions.vite.alias is deprecated, will auto-resolve from chainWebpack / configureWebpack`,
29+
chalk.cyan(`[${name}]: pluginOptions.vite.alias is deprecated, will auto-resolve from chainWebpack / configureWebpack`),
2730
)
2831
}
2932

@@ -33,13 +36,11 @@ const useMPA = Boolean(vueConfig.pages)
3336
export default defineConfig({
3437
plugins: [
3538
envCompatible(),
39+
htmlTemplate({ mpa: useMPA }),
3640
vueCli(),
3741
createVuePlugin(viteOptions.vitePluginVue2Options),
3842
useMPA
39-
? mpa({
40-
// special use main.html for vue-cli
41-
filename: 'main.html',
42-
})
43+
? mpa()
4344
: undefined,
4445
...extraPlugins,
4546
],

examples/my-mpa-ts-app/src/pages/index/main.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/my-mpa-ts-app/src/pages/subpage/main.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/my-spa-js-app/index.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

generator/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { writeHtmlFromPublic, writeMainDotHtml4EachEntry } = require('../lib/utils')
1+
const pkgJson = require('../package.json')
22

33
module.exports = (api, options = {}) => {
44
// 1. extend package
@@ -10,16 +10,10 @@ module.exports = (api, options = {}) => {
1010
api.extendPackage(pkg)
1111

1212
// 2. render template
13-
api.render('./template')
13+
api.render('./template', { pkgName: pkgJson.name })
1414

1515
// 3. logger
1616
api.onCreateComplete(() => {
17-
const root = api.resolve('.')
18-
if (options.htmlInitMethod === 'vue-cli') {
19-
writeHtmlFromPublic(root)
20-
} else {
21-
writeMainDotHtml4EachEntry(root)
22-
}
2317
api.exitLog('use vite for development by `yarn vite`', 'info')
2418
})
2519
}

generator/template/bin/vite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const path = require('path')
44
const { spawn } = require('child_process')
5-
const configPath = require.resolve('vue-cli-plugin-vite/config/index.ts')
5+
const configPath = require.resolve('<%- pkgName %>/config/index.ts')
66
const cwd = path.resolve(__dirname, '../')
77

88
const params = [

lib/utils.js

Lines changed: 0 additions & 102 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
"url": "https://github.com/IndexXuan/vue-cli-plugin-vite/issues"
2424
},
2525
"keywords": [
26+
"vite-plguin",
2627
"vue-cli-plugin",
2728
"vite"
2829
],
2930
"dependencies": {
3031
"chalk": "4.1.0",
3132
"vite": "2.1.5",
3233
"vite-plugin-env-compatible": "0.2.1",
34+
"vite-plugin-html-template": "0.1.0",
3335
"vite-plugin-mpa": "0.3.1",
3436
"vite-plugin-vue-cli": "0.7.1",
3537
"vite-plugin-vue2": "1.4.3"

0 commit comments

Comments
 (0)