Skip to content

Commit b5d8943

Browse files
committed
'mpvue项目初次提交'
0 parents  commit b5d8943

34 files changed

+12996
-0
lines changed

.babelrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
9+
"stage-2"
10+
],
11+
"plugins": ["transform-runtime"],
12+
"env": {
13+
"test": {
14+
"presets": ["env", "stage-2"],
15+
"plugins": ["istanbul"]
16+
}
17+
}
18+
}

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*.js
2+
config/*.js

.eslintrc.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// http://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
root: true,
5+
parser: 'babel-eslint',
6+
parserOptions: {
7+
sourceType: 'module'
8+
},
9+
env: {
10+
browser: false,
11+
node: true,
12+
es6: true
13+
},
14+
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
15+
extends: 'standard',
16+
// required to lint *.vue files
17+
plugins: [
18+
'html'
19+
],
20+
// add your custom rules here
21+
'rules': {
22+
// allow paren-less arrow functions
23+
'arrow-parens': 0,
24+
// allow async-await
25+
'generator-star-spacing': 0,
26+
// allow debugger during development
27+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
28+
},
29+
globals: {
30+
App: true,
31+
Page: true,
32+
wx: true,
33+
swan: true,
34+
tt: true,
35+
my: true,
36+
getApp: true,
37+
getPage: true,
38+
requirePlugin: true,
39+
mpvue: true,
40+
mpvuePlatform: true
41+
}
42+
}

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules/
3+
dist/
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Editor directories and files
9+
.idea
10+
*.suo
11+
*.ntvs*
12+
*.njsproj
13+
*.sln

.postcssrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://github.com/michael-ciniawsky/postcss-load-config
2+
3+
module.exports = {
4+
"plugins": {
5+
"postcss-mpvue-wxss": {}
6+
}
7+
}

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# mpvue-imooc-ebook
2+
3+
> A Mpvue project
4+
5+
## Build Setup
6+
7+
``` bash
8+
# 初始化项目
9+
vue init mpvue/mpvue-quickstart myproject
10+
cd myproject
11+
12+
# 安装依赖
13+
yarn
14+
15+
# 开发时构建
16+
npm dev
17+
18+
# 打包构建
19+
npm build
20+
21+
# 指定平台的开发时构建(微信、百度、头条、支付宝)
22+
npm dev:wx
23+
npm dev:swan
24+
npm dev:tt
25+
npm dev:my
26+
27+
# 指定平台的打包构建
28+
npm build:wx
29+
npm build:swan
30+
npm build:tt
31+
npm build:my
32+
33+
# 生成 bundle 分析报告
34+
npm run build --report
35+
```
36+
37+
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).

build/build.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require('./check-versions')()
2+
3+
process.env.NODE_ENV = 'production'
4+
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx'
5+
6+
var ora = require('ora')
7+
var rm = require('rimraf')
8+
var path = require('path')
9+
var chalk = require('chalk')
10+
var webpack = require('webpack')
11+
var config = require('../config')
12+
var webpackConfig = require('./webpack.prod.conf')
13+
var utils = require('./utils')
14+
15+
var spinner = ora('building for production...')
16+
spinner.start()
17+
18+
rm(path.join(config.build.assetsRoot, '*'), err => {
19+
if (err) throw err
20+
webpack(webpackConfig, function (err, stats) {
21+
spinner.stop()
22+
if (err) throw err
23+
if (process.env.PLATFORM === 'swan') {
24+
utils.writeFrameworkinfo()
25+
}
26+
process.stdout.write(stats.toString({
27+
colors: true,
28+
modules: false,
29+
children: false,
30+
chunks: false,
31+
chunkModules: false
32+
}) + '\n\n')
33+
34+
if (stats.hasErrors()) {
35+
console.log(chalk.red(' Build failed with errors.\n'))
36+
process.exit(1)
37+
}
38+
39+
console.log(chalk.cyan(' Build complete.\n'))
40+
console.log(chalk.yellow(
41+
' Tip: built files are meant to be served over an HTTP server.\n' +
42+
' Opening index.html over file:// won\'t work.\n'
43+
))
44+
})
45+
})

build/check-versions.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var chalk = require('chalk')
2+
var semver = require('semver')
3+
var packageConfig = require('../package.json')
4+
var shell = require('shelljs')
5+
function exec (cmd) {
6+
return require('child_process').execSync(cmd).toString().trim()
7+
}
8+
9+
var versionRequirements = [
10+
{
11+
name: 'node',
12+
currentVersion: semver.clean(process.version),
13+
versionRequirement: packageConfig.engines.node
14+
}
15+
]
16+
17+
if (shell.which('npm')) {
18+
versionRequirements.push({
19+
name: 'npm',
20+
currentVersion: exec('npm --version'),
21+
versionRequirement: packageConfig.engines.npm
22+
})
23+
}
24+
25+
module.exports = function () {
26+
var warnings = []
27+
for (var i = 0; i < versionRequirements.length; i++) {
28+
var mod = versionRequirements[i]
29+
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30+
warnings.push(mod.name + ': ' +
31+
chalk.red(mod.currentVersion) + ' should be ' +
32+
chalk.green(mod.versionRequirement)
33+
)
34+
}
35+
}
36+
37+
if (warnings.length) {
38+
console.log('')
39+
console.log(chalk.yellow('To use this template, you must update following to modules:'))
40+
console.log()
41+
for (var i = 0; i < warnings.length; i++) {
42+
var warning = warnings[i]
43+
console.log(' ' + warning)
44+
}
45+
console.log()
46+
process.exit(1)
47+
}
48+
}

build/dev-client.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
require('eventsource-polyfill')
3+
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4+
5+
hotClient.subscribe(function (event) {
6+
if (event.action === 'reload') {
7+
window.location.reload()
8+
}
9+
})

build/dev-server.js

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
require('./check-versions')()
2+
3+
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx'
4+
var config = require('../config')
5+
if (!process.env.NODE_ENV) {
6+
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
7+
}
8+
9+
// var opn = require('opn')
10+
var path = require('path')
11+
var express = require('express')
12+
var webpack = require('webpack')
13+
var proxyMiddleware = require('http-proxy-middleware')
14+
var portfinder = require('portfinder')
15+
var webpackConfig = require('./webpack.dev.conf')
16+
var utils = require('./utils')
17+
18+
// default port where dev server listens for incoming traffic
19+
var port = process.env.PORT || config.dev.port
20+
// automatically open browser, if not set will be false
21+
var autoOpenBrowser = !!config.dev.autoOpenBrowser
22+
// Define HTTP proxies to your custom API backend
23+
// https://github.com/chimurai/http-proxy-middleware
24+
var proxyTable = config.dev.proxyTable
25+
26+
var app = express()
27+
var compiler = webpack(webpackConfig)
28+
if (process.env.PLATFORM === 'swan') {
29+
utils.writeFrameworkinfo()
30+
}
31+
32+
// var devMiddleware = require('webpack-dev-middleware')(compiler, {
33+
// publicPath: webpackConfig.output.publicPath,
34+
// quiet: true
35+
// })
36+
37+
// var hotMiddleware = require('webpack-hot-middleware')(compiler, {
38+
// log: false,
39+
// heartbeat: 2000
40+
// })
41+
// force page reload when html-webpack-plugin template changes
42+
// compiler.plugin('compilation', function (compilation) {
43+
// compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
44+
// hotMiddleware.publish({ action: 'reload' })
45+
// cb()
46+
// })
47+
// })
48+
49+
// proxy api requests
50+
Object.keys(proxyTable).forEach(function (context) {
51+
var options = proxyTable[context]
52+
if (typeof options === 'string') {
53+
options = { target: options }
54+
}
55+
app.use(proxyMiddleware(options.filter || context, options))
56+
})
57+
58+
// handle fallback for HTML5 history API
59+
app.use(require('connect-history-api-fallback')())
60+
61+
// serve webpack bundle output
62+
// app.use(devMiddleware)
63+
64+
// enable hot-reload and state-preserving
65+
// compilation error display
66+
// app.use(hotMiddleware)
67+
68+
// serve pure static assets
69+
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
70+
app.use(staticPath, express.static('./static'))
71+
72+
// var uri = 'http://localhost:' + port
73+
74+
var _resolve
75+
var readyPromise = new Promise(resolve => {
76+
_resolve = resolve
77+
})
78+
79+
// console.log('> Starting dev server...')
80+
// devMiddleware.waitUntilValid(() => {
81+
// console.log('> Listening at ' + uri + '\n')
82+
// // when env is testing, don't need open it
83+
// if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
84+
// opn(uri)
85+
// }
86+
// _resolve()
87+
// })
88+
89+
module.exports = new Promise((resolve, reject) => {
90+
portfinder.basePort = port
91+
portfinder.getPortPromise()
92+
.then(newPort => {
93+
if (port !== newPort) {
94+
console.log(`${port}端口被占用,开启新端口${newPort}`)
95+
}
96+
var server = app.listen(newPort, 'localhost')
97+
// for 小程序的文件保存机制
98+
require('webpack-dev-middleware-hard-disk')(compiler, {
99+
publicPath: webpackConfig.output.publicPath,
100+
quiet: true
101+
})
102+
resolve({
103+
ready: readyPromise,
104+
close: () => {
105+
server.close()
106+
}
107+
})
108+
}).catch(error => {
109+
console.log('没有找到空闲端口,请打开任务管理器杀死进程端口再试', error)
110+
})
111+
})

0 commit comments

Comments
 (0)