mirror of
https://gitee.com/dcloud/uni-preset-vue
synced 2025-04-29 08:20:12 +08:00
init
This commit is contained in:
parent
1c9bd95d50
commit
9cd49e725a
12
LICENSE
Normal file → Executable file
12
LICENSE
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2018 DCloud
|
Copyright (c) 2017-present, Yuxi (Evan) You
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in
|
||||||
copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
# uni-preset-vue
|
# @uni-app/vue-cli-preset-uni-app
|
||||||
uni-app preset for vue
|
|
||||||
|
> uni-app plugin for vue-cli
|
90
generator.js
Normal file
90
generator.js
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
|
||||||
|
async function generate(dir, files, base = '') {
|
||||||
|
|
||||||
|
const globby = require('globby')
|
||||||
|
|
||||||
|
const _files = await globby(['**/*'], {
|
||||||
|
cwd: dir
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const rawPath of _files) {
|
||||||
|
files[path.join(base, rawPath)] = fs.readFileSync(path.resolve(dir, rawPath), 'utf-8')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (api, options, rootOptions) => {
|
||||||
|
|
||||||
|
api.render(async function(files) {
|
||||||
|
|
||||||
|
api.extendPackage({
|
||||||
|
dependencies: {
|
||||||
|
'@dcloudio/uni-h5': '^0.0.1'
|
||||||
|
},
|
||||||
|
devDependencies: {
|
||||||
|
'@dcloudio/vue-cli-plugin-uni': '^0.0.1'
|
||||||
|
},
|
||||||
|
babel: {
|
||||||
|
presets: [
|
||||||
|
['@vue/app', {
|
||||||
|
useBuiltIns: 'entry'
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
browserslist: [
|
||||||
|
'last 3 versions',
|
||||||
|
'Android >= 4.4',
|
||||||
|
'ios >= 8'
|
||||||
|
],
|
||||||
|
vue: {
|
||||||
|
baseUrl: '/',
|
||||||
|
assetsDir: 'static'
|
||||||
|
},
|
||||||
|
vuePlugins: {
|
||||||
|
service: [path.resolve(__dirname, '../vue-cli-plugin-uni-app')]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.keys(files).forEach(name => {
|
||||||
|
delete files[name]
|
||||||
|
})
|
||||||
|
|
||||||
|
const template = options.repo || options.template
|
||||||
|
|
||||||
|
const base = 'src'
|
||||||
|
|
||||||
|
if (template === 'default') {
|
||||||
|
await generate(path.resolve(__dirname, './template/default'), files, base)
|
||||||
|
} else {
|
||||||
|
const ora = require('ora')
|
||||||
|
const home = require('user-home')
|
||||||
|
const download = require('download-git-repo')
|
||||||
|
|
||||||
|
const spinner = ora('模板下载中...')
|
||||||
|
spinner.start()
|
||||||
|
|
||||||
|
const tmp = path.join(home, '.uni-app/templates', template.replace(/[\/:]/g, '-'), 'src')
|
||||||
|
|
||||||
|
if (fs.existsSync(tmp)) {
|
||||||
|
require('rimraf').sync.rm(tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
download(template, tmp, err => {
|
||||||
|
spinner.stop()
|
||||||
|
if (err) {
|
||||||
|
return reject(err)
|
||||||
|
}
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
await generate(tmp, files, base)
|
||||||
|
}
|
||||||
|
|
||||||
|
await generate(path.resolve(__dirname, './template/common'), files)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "uni-preset-vue",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "uni-app preset for vue-cli",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "fxy060608",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"download-git-repo": "^1.1.0",
|
||||||
|
"globby": "^8.0.1",
|
||||||
|
"ora": "^3.0.0",
|
||||||
|
"rimraf": "^2.6.2",
|
||||||
|
"user-home": "^2.0.0"
|
||||||
|
}
|
||||||
|
}
|
12
preset.json
Normal file
12
preset.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"useConfigFiles": false,
|
||||||
|
"plugins": {
|
||||||
|
"@vue/cli-plugin-babel": {
|
||||||
|
"presets": [
|
||||||
|
["@vue/app", {
|
||||||
|
"useBuiltIns": "entry"
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
prompts.js
Normal file
43
prompts.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
module.exports = [{
|
||||||
|
type: 'list',
|
||||||
|
name: 'template',
|
||||||
|
message: '请选择 uni-app 模板',
|
||||||
|
choices: [{
|
||||||
|
name: '默认模板',
|
||||||
|
value: 'default'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Hello uni-app',
|
||||||
|
value: 'direct:https://www.inkercloud.com/masterkong/hello-uniapp.zip'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '登录模板',
|
||||||
|
value: 'hello uni-app'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '看图模板',
|
||||||
|
value: 'hello uni-app'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '自定义模板',
|
||||||
|
value: 'custom'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
default: 'None',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
when: answers => answers.template === 'custom',
|
||||||
|
type: 'input',
|
||||||
|
name: 'repo',
|
||||||
|
message: '请输入自定义 uni-app 模板地址',
|
||||||
|
filter(input) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
if (input) {
|
||||||
|
resolve(input)
|
||||||
|
} else {
|
||||||
|
reject('uni-app 模板地址不能为空')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
9
template/common/postcss.config.js
Normal file
9
template/common/postcss.config.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const pkg = require('./package.json')
|
||||||
|
module.exports = {
|
||||||
|
plugins: [
|
||||||
|
require("autoprefixer")({
|
||||||
|
browsers: pkg.browserslist
|
||||||
|
}),
|
||||||
|
// require("./packages/@uni-app/postcss")
|
||||||
|
]
|
||||||
|
}
|
27
template/common/public/index.html
Normal file
27
template/common/public/index.html
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<title>
|
||||||
|
<%= htmlWebpackPlugin.options.title %>
|
||||||
|
</title>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<link rel="stylesheet" href="<%= htmlWebpackPlugin.options.baseUrl %>static/index.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
<strong>Please enable JavaScript to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
22
template/default/App.vue
Normal file
22
template/default/App.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
onLaunch: function () {
|
||||||
|
console.log('App Launch')
|
||||||
|
},
|
||||||
|
onShow: function () {
|
||||||
|
console.log('App Show')
|
||||||
|
},
|
||||||
|
onHide: function () {
|
||||||
|
console.log('App Hide')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/*每个页面公共css */
|
||||||
|
|
||||||
|
page,
|
||||||
|
view {
|
||||||
|
display: flex;/* uni-app默认使用flex布局。因为flex布局有利于跨更多平台,尤其是采用原生渲染的平台。如不了解flex布局,请参考http://www.w3.org/TR/css3-flexbox/。若不需要flex布局可删除本行*/
|
||||||
|
}
|
||||||
|
</style>
|
11
template/default/main.js
Normal file
11
template/default/main.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import App from './App'
|
||||||
|
|
||||||
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
App.mpType = 'app'
|
||||||
|
|
||||||
|
const app = new Vue({
|
||||||
|
...App
|
||||||
|
})
|
||||||
|
app.$mount()
|
55
template/default/manifest.json
Normal file
55
template/default/manifest.json
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"name" : "test-uni-app",
|
||||||
|
"appid" : "__UNI__058126D",
|
||||||
|
"description": "",
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"versionCode": "100",
|
||||||
|
"transformPx":false,
|
||||||
|
"app-plus": { /* 5+App特有相关 */
|
||||||
|
"modules": { /* 模块配置 */
|
||||||
|
|
||||||
|
},
|
||||||
|
"distribute": { /* 应用发布信息 */
|
||||||
|
"android": { /* android打包配置 */
|
||||||
|
"permissions": ["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ios": { /* ios打包配置 */
|
||||||
|
|
||||||
|
},
|
||||||
|
"sdkConfigs": { /* SDK配置 */
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"quickapp": { /* 快应用特有相关 */
|
||||||
|
|
||||||
|
},
|
||||||
|
"mp-weixin": { /* 小程序特有相关 */
|
||||||
|
"appid": "",
|
||||||
|
"setting" : {
|
||||||
|
"urlCheck" : true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
template/default/pages.json
Normal file
16
template/default/pages.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
||||||
|
{
|
||||||
|
"path": "pages/index/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "uni-app"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalStyle": {
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"navigationBarTitleText": "uni-app",
|
||||||
|
"navigationBarBackgroundColor": "#F8F8F8",
|
||||||
|
"backgroundColor": "#F8F8F8"
|
||||||
|
}
|
||||||
|
}
|
28
template/default/pages/index/index.vue
Normal file
28
template/default/pages/index/index.vue
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<template>
|
||||||
|
<view class="content">
|
||||||
|
<text class="title">{{title}}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
title: 'Hello'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 36upx;
|
||||||
|
color: #8f8f94;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
x
Reference in New Issue
Block a user