Skip to content

Commit 5ec5a98

Browse files
committed
feat: support build
1 parent 07478d6 commit 5ec5a98

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ yarn vite // or npm run vite
174174
- ✅ also resolved from `vue.config.js#runtimeCompiler`
175175
- ✅ MPA Support
176176
- ✅ same development experience and build result
177+
- ✅ Build Support (as of 1.0.0-rc.0, no real html entry file generated, just reuse public/index.html of vue-cli)
178+
- ✅ Support SPA Build
179+
- ✅ Support MPA Build
177180
- ✅ Special Synatax
178181
- ❌ require('xxx') or require('xxx').default, most of the case, it can be replaced by dynamicImport ( import('xxx') or import('xxx').then(module => module.default) )
179182
- ❌ '~some-module' syntax for Import CSS (maybe [#2185](https://github.com/vitejs/vite/issues/2185#issuecomment-784637827))

config/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ let vueConfig: VueCliOptions = {}
1616
try {
1717
vueConfig = require(resolve('vue.config.js')) || {}
1818
} catch (e) {
19-
console.error(chalk.redBright(e))
19+
if (process.env.VITE_DEBUG) {
20+
console.error(chalk.redBright(e))
21+
}
2022
/**/
2123
}
2224

@@ -36,7 +38,8 @@ const useMPA = Boolean(vueConfig.pages)
3638
export default defineConfig({
3739
plugins: [
3840
envCompatible(),
39-
htmlTemplate({ mpa: useMPA }),
41+
// auto infer pages
42+
htmlTemplate({ pages: vueConfig.pages || {} }),
4043
vueCli(),
4144
createVuePlugin(viteOptions.vitePluginVue2Options),
4245
useMPA

examples/my-mpa-ts-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"lint-staged": "^9.5.0",
3131
"prettier": "^1.19.1",
3232
"typescript": "~3.9.3",
33-
"vue-cli-plugin-vite": "0.3.0",
33+
"vue-cli-plugin-vite": "1.0.0-rc.0",
3434
"vue-template-compiler": "^2.6.11"
3535
},
3636
"eslintConfig": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title><%= htmlWebpackPlugin.options.title %>template</title>
9+
</head>
10+
<body>
11+
<noscript>
12+
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13+
</noscript>
14+
<div id="app"></div>
15+
<!-- built files will be auto injected -->
16+
</body>
17+
</html>

examples/my-mpa-ts-app/vue.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ module.exports = {
44
disableHostCheck: true,
55
},
66
pages: {
7-
index: 'src/pages/index/main.ts',
7+
index: {
8+
entry: 'src/pages/index/main.ts',
9+
title: '首页',
10+
template: './src/pages/index/main.html',
11+
},
12+
subpage: 'src/pages/subpage/main.ts',
813
},
914
}

examples/my-spa-js-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"babel-eslint": "^10.1.0",
2121
"eslint": "^6.7.2",
2222
"eslint-plugin-vue": "^6.2.2",
23-
"vue-cli-plugin-vite": "0.3.0",
23+
"vue-cli-plugin-vite": "1.0.0-rc.0",
2424
"vue-template-compiler": "^2.6.11"
2525
},
2626
"eslintConfig": {

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"build": "echo build success",
1212
"test:spa-js": "cd ./examples/my-spa-js-app && npm i && yarn vite:build && yarn build",
1313
"test:mpa-ts": "cd ./examples/my-mpa-ts-app && npm i && yarn vite:build && yarn build",
14-
"test:unit": "npm run test:spa-js & npm run test:mpa-ts",
15-
"test": "echo missing test",
14+
"test": "npm run test:spa-js & npm run test:mpa-ts",
1615
"toc": "npx markdown-toc -i --bullets=- README.md",
1716
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
1817
},
@@ -32,7 +31,7 @@
3231
"chalk": "4.1.0",
3332
"vite": "2.1.5",
3433
"vite-plugin-env-compatible": "0.2.1",
35-
"vite-plugin-html-template": "0.1.0",
34+
"vite-plugin-html-template": "0.2.0",
3635
"vite-plugin-mpa": "0.3.1",
3736
"vite-plugin-vue-cli": "0.7.1",
3837
"vite-plugin-vue2": "1.4.3"

0 commit comments

Comments
 (0)