-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Starrah/ZYN
创建前端mpvue示例项目
- Loading branch information
Showing
45 changed files
with
12,093 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,18 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"modules": false, | ||
"targets": { | ||
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"] | ||
} | ||
}], | ||
"stage-2" | ||
], | ||
"plugins": ["transform-runtime"], | ||
"env": { | ||
"test": { | ||
"presets": ["env", "stage-2"], | ||
"plugins": ["istanbul"] | ||
} | ||
} | ||
} |
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,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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,2 @@ | ||
build/*.js | ||
config/*.js |
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,42 @@ | ||
// http://eslint.org/docs/user-guide/configuring | ||
|
||
module.exports = { | ||
root: true, | ||
parser: 'babel-eslint', | ||
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
env: { | ||
browser: false, | ||
node: true, | ||
es6: true | ||
}, | ||
// https://github.com/standard/standard/blob/master/docs/RULES-en.md | ||
extends: 'standard', | ||
// required to lint *.vue files | ||
plugins: [ | ||
'html' | ||
], | ||
// add your custom rules here | ||
'rules': { | ||
// allow paren-less arrow functions | ||
'arrow-parens': 0, | ||
// allow async-await | ||
'generator-star-spacing': 0, | ||
// allow debugger during development | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 | ||
}, | ||
globals: { | ||
App: true, | ||
Page: true, | ||
wx: true, | ||
swan: true, | ||
tt: true, | ||
my: true, | ||
getApp: true, | ||
getPage: true, | ||
requirePlugin: true, | ||
mpvue: true, | ||
mpvuePlatform: true | ||
} | ||
} |
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,13 @@ | ||
.DS_Store | ||
node_modules/ | ||
dist/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln |
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,7 @@ | ||
// https://github.com/michael-ciniawsky/postcss-load-config | ||
|
||
module.exports = { | ||
"plugins": { | ||
"postcss-mpvue-wxss": {} | ||
} | ||
} |
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,37 @@ | ||
# frontend | ||
|
||
> 2019软件工程T01组课程项目 清华校友圈子微信小程序 | ||
## Build Setup | ||
|
||
``` bash | ||
# 初始化项目 | ||
vue init mpvue/mpvue-quickstart myproject | ||
cd myproject | ||
|
||
# 安装依赖 | ||
yarn | ||
|
||
# 开发时构建 | ||
npm dev | ||
|
||
# 打包构建 | ||
npm build | ||
|
||
# 指定平台的开发时构建(微信、百度、头条、支付宝) | ||
npm dev:wx | ||
npm dev:swan | ||
npm dev:tt | ||
npm dev:my | ||
|
||
# 指定平台的打包构建 | ||
npm build:wx | ||
npm build:swan | ||
npm build:tt | ||
npm build:my | ||
|
||
# 生成 bundle 分析报告 | ||
npm run build --report | ||
``` | ||
|
||
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). |
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,45 @@ | ||
require('./check-versions')() | ||
|
||
process.env.NODE_ENV = 'production' | ||
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx' | ||
|
||
var ora = require('ora') | ||
var rm = require('rimraf') | ||
var path = require('path') | ||
var chalk = require('chalk') | ||
var webpack = require('webpack') | ||
var config = require('../config') | ||
var webpackConfig = require('./webpack.prod.conf') | ||
var utils = require('./utils') | ||
|
||
var spinner = ora('building for production...') | ||
spinner.start() | ||
|
||
rm(path.join(config.build.assetsRoot, '*'), err => { | ||
if (err) throw err | ||
webpack(webpackConfig, function (err, stats) { | ||
spinner.stop() | ||
if (err) throw err | ||
if (process.env.PLATFORM === 'swan') { | ||
utils.writeFrameworkinfo() | ||
} | ||
process.stdout.write(stats.toString({ | ||
colors: true, | ||
modules: false, | ||
children: false, | ||
chunks: false, | ||
chunkModules: false | ||
}) + '\n\n') | ||
|
||
if (stats.hasErrors()) { | ||
console.log(chalk.red(' Build failed with errors.\n')) | ||
process.exit(1) | ||
} | ||
|
||
console.log(chalk.cyan(' Build complete.\n')) | ||
console.log(chalk.yellow( | ||
' Tip: built files are meant to be served over an HTTP server.\n' + | ||
' Opening index.html over file:// won\'t work.\n' | ||
)) | ||
}) | ||
}) |
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,48 @@ | ||
var chalk = require('chalk') | ||
var semver = require('semver') | ||
var packageConfig = require('../package.json') | ||
var shell = require('shelljs') | ||
function exec (cmd) { | ||
return require('child_process').execSync(cmd).toString().trim() | ||
} | ||
|
||
var versionRequirements = [ | ||
{ | ||
name: 'node', | ||
currentVersion: semver.clean(process.version), | ||
versionRequirement: packageConfig.engines.node | ||
} | ||
] | ||
|
||
if (shell.which('npm')) { | ||
versionRequirements.push({ | ||
name: 'npm', | ||
currentVersion: exec('npm --version'), | ||
versionRequirement: packageConfig.engines.npm | ||
}) | ||
} | ||
|
||
module.exports = function () { | ||
var warnings = [] | ||
for (var i = 0; i < versionRequirements.length; i++) { | ||
var mod = versionRequirements[i] | ||
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { | ||
warnings.push(mod.name + ': ' + | ||
chalk.red(mod.currentVersion) + ' should be ' + | ||
chalk.green(mod.versionRequirement) | ||
) | ||
} | ||
} | ||
|
||
if (warnings.length) { | ||
console.log('') | ||
console.log(chalk.yellow('To use this template, you must update following to modules:')) | ||
console.log() | ||
for (var i = 0; i < warnings.length; i++) { | ||
var warning = warnings[i] | ||
console.log(' ' + warning) | ||
} | ||
console.log() | ||
process.exit(1) | ||
} | ||
} |
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,9 @@ | ||
/* eslint-disable */ | ||
require('eventsource-polyfill') | ||
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') | ||
|
||
hotClient.subscribe(function (event) { | ||
if (event.action === 'reload') { | ||
window.location.reload() | ||
} | ||
}) |
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,111 @@ | ||
require('./check-versions')() | ||
|
||
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx' | ||
var config = require('../config') | ||
if (!process.env.NODE_ENV) { | ||
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) | ||
} | ||
|
||
// var opn = require('opn') | ||
var path = require('path') | ||
var express = require('express') | ||
var webpack = require('webpack') | ||
var proxyMiddleware = require('http-proxy-middleware') | ||
var portfinder = require('portfinder') | ||
var webpackConfig = require('./webpack.dev.conf') | ||
var utils = require('./utils') | ||
|
||
// default port where dev server listens for incoming traffic | ||
var port = process.env.PORT || config.dev.port | ||
// automatically open browser, if not set will be false | ||
var autoOpenBrowser = !!config.dev.autoOpenBrowser | ||
// Define HTTP proxies to your custom API backend | ||
// https://github.com/chimurai/http-proxy-middleware | ||
var proxyTable = config.dev.proxyTable | ||
|
||
var app = express() | ||
var compiler = webpack(webpackConfig) | ||
if (process.env.PLATFORM === 'swan') { | ||
utils.writeFrameworkinfo() | ||
} | ||
|
||
// var devMiddleware = require('webpack-dev-middleware')(compiler, { | ||
// publicPath: webpackConfig.output.publicPath, | ||
// quiet: true | ||
// }) | ||
|
||
// var hotMiddleware = require('webpack-hot-middleware')(compiler, { | ||
// log: false, | ||
// heartbeat: 2000 | ||
// }) | ||
// force page reload when html-webpack-plugin template changes | ||
// compiler.plugin('compilation', function (compilation) { | ||
// compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { | ||
// hotMiddleware.publish({ action: 'reload' }) | ||
// cb() | ||
// }) | ||
// }) | ||
|
||
// proxy api requests | ||
Object.keys(proxyTable).forEach(function (context) { | ||
var options = proxyTable[context] | ||
if (typeof options === 'string') { | ||
options = { target: options } | ||
} | ||
app.use(proxyMiddleware(options.filter || context, options)) | ||
}) | ||
|
||
// handle fallback for HTML5 history API | ||
app.use(require('connect-history-api-fallback')()) | ||
|
||
// serve webpack bundle output | ||
// app.use(devMiddleware) | ||
|
||
// enable hot-reload and state-preserving | ||
// compilation error display | ||
// app.use(hotMiddleware) | ||
|
||
// serve pure static assets | ||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) | ||
app.use(staticPath, express.static('./static')) | ||
|
||
// var uri = 'http://localhost:' + port | ||
|
||
var _resolve | ||
var readyPromise = new Promise(resolve => { | ||
_resolve = resolve | ||
}) | ||
|
||
// console.log('> Starting dev server...') | ||
// devMiddleware.waitUntilValid(() => { | ||
// console.log('> Listening at ' + uri + '\n') | ||
// // when env is testing, don't need open it | ||
// if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { | ||
// opn(uri) | ||
// } | ||
// _resolve() | ||
// }) | ||
|
||
module.exports = new Promise((resolve, reject) => { | ||
portfinder.basePort = port | ||
portfinder.getPortPromise() | ||
.then(newPort => { | ||
if (port !== newPort) { | ||
console.log(`${port}端口被占用,开启新端口${newPort}`) | ||
} | ||
var server = app.listen(newPort, 'localhost') | ||
// for 小程序的文件保存机制 | ||
require('webpack-dev-middleware-hard-disk')(compiler, { | ||
publicPath: webpackConfig.output.publicPath, | ||
quiet: true | ||
}) | ||
resolve({ | ||
ready: readyPromise, | ||
close: () => { | ||
server.close() | ||
} | ||
}) | ||
}).catch(error => { | ||
console.log('没有找到空闲端口,请打开任务管理器杀死进程端口再试', error) | ||
}) | ||
}) |
Oops, something went wrong.