Skip to content

Commit c84ea26

Browse files
committed
init project
1 parent 0866970 commit c84ea26

27 files changed

+576
-295
lines changed

README.md

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,16 @@
1-
# vue-webpack-boilerplate
1+
# mpvue-quickstart
22

3-
> A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.
4-
5-
> This template is Vue 2.0 compatible. For Vue 1.x use this command: `vue init webpack#1.0 my-project`
6-
7-
## Documentation
8-
9-
- [For this template](http://vuejs-templates.github.io/webpack): common questions specific to this template are answered and each part is described in greater detail
10-
- [For Vue 2.0](http://vuejs.org/guide/): general information about how to work with Vue, not specific to this template
11-
12-
## Usage
13-
14-
This is a project template for [vue-cli](https://github.com/vuejs/vue-cli). **It is recommended to use npm 3+ for a more efficient dependency tree.**
3+
> fork 自 [vuejs-templates/webpack](https://github.com/vuejs-templates/webpack)修改而来。
154
5+
## 基本用法
166
``` bash
177
$ npm install -g vue-cli
18-
$ vue init webpack my-project
8+
$ vue init mpvue/mpvue-quickstart my-project
199
$ cd my-project
2010
$ npm install
2111
$ npm run dev
2212
```
2313

24-
If port 8080 is already in use on your machine you must change the port number in `/config/index.js`. Otherwise `npm run dev` will fail.
25-
26-
## What's Included
27-
28-
- `npm run dev`: first-in-class development experience.
29-
- Webpack + `vue-loader` for single file Vue components.
30-
- State preserving hot-reload
31-
- State preserving compilation error overlay
32-
- Lint-on-save with ESLint
33-
- Source maps
14+
更多详细文档请查阅 [quickstart](http://mpvue.com/mpvue/quickstart/)
3415

35-
- `npm run build`: Production ready build.
36-
- JavaScript minified with [UglifyJS](https://github.com/mishoo/UglifyJS2).
37-
- HTML minified with [html-minifier](https://github.com/kangax/html-minifier).
38-
- CSS across all components extracted into a single file and minified with [cssnano](https://github.com/ben-eb/cssnano).
39-
- All static assets compiled with version hashes for efficient long-term caching, and a production `index.html` is auto-generated with proper URLs to these generated assets.
40-
- Use `npm run build --report`to build with bundle size analytics.
41-
42-
- `npm run unit`: Unit tests run in PhantomJS with [Karma](http://karma-runner.github.io/0.13/index.html) + [Mocha](http://mochajs.org/) + [karma-webpack](https://github.com/webpack/karma-webpack).
43-
- Supports ES2015+ in test files.
44-
- Supports all webpack loaders.
45-
- Easy mock injection.
46-
47-
- `npm run e2e`: End-to-end tests with [Nightwatch](http://nightwatchjs.org/).
48-
- Run tests in multiple browsers in parallel.
49-
- Works with one command out of the box:
50-
- Selenium and chromedriver dependencies automatically handled.
51-
- Automatically spawns the Selenium server.
52-
53-
### Fork It And Make Your Own
54-
55-
You can fork this repo to create your own boilerplate, and use it with `vue-cli`:
56-
57-
``` bash
58-
vue init username/repo my-project
59-
```
16+
bug 或者交流建议等请反馈到 [mpvue/issues](https://github.com/Meituan-Dianping/mpvue/issues)

meta.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ module.exports = {
2828
"type": "list",
2929
"message": "Vue build",
3030
"choices": [
31+
// {
32+
// "name": "Runtime + Compiler: recommended for most users",
33+
// "value": "standalone",
34+
// "short": "standalone"
35+
// },
3136
{
32-
"name": "Runtime + Compiler: recommended for most users",
33-
"value": "standalone",
34-
"short": "standalone"
35-
},
36-
{
37-
"name": "Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere",
37+
"name": "Runtime-only: no custom render function, only can compile template in *.vue",
3838
"value": "runtime",
3939
"short": "runtime"
4040
}
4141
]
4242
},
43-
"router": {
43+
"vuex": {
4444
"type": "confirm",
45-
"message": "Install vue-router?"
45+
"message": "Use Vuex?"
4646
},
4747
"lint": {
4848
"type": "confirm",
@@ -70,23 +70,24 @@ module.exports = {
7070
}
7171
]
7272
},
73-
"unit": {
74-
"type": "confirm",
75-
"message": "Setup unit tests with Karma + Mocha?"
76-
},
77-
"e2e": {
78-
"type": "confirm",
79-
"message": "Setup e2e tests with Nightwatch?"
73+
"test": {
74+
"value": false,
75+
"message": "小程序测试,敬请关注最新微信开发者工具的“测试报告”功能"
8076
}
8177
},
8278
"filters": {
8379
".eslintrc.js": "lint",
8480
".eslintignore": "lint",
85-
"config/test.env.js": "unit || e2e",
86-
"test/unit/**/*": "unit",
87-
"build/webpack.test.conf.js": "unit",
88-
"test/e2e/**/*": "e2e",
89-
"src/router/**/*": "router"
81+
// "config/test.env.js": "unit || e2e",
82+
// "test/unit/**/*": "unit",
83+
// "build/webpack.test.conf.js": "unit",
84+
// "test/e2e/**/*": "e2e"
85+
"config/test.env.js": "test",
86+
"test/unit/**/*": "test",
87+
"build/webpack.test.conf.js": "test",
88+
"test/e2e/**/*": "test",
89+
"src/pages/counter/*": "vuex",
9090
},
91-
"completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack"
91+
// "completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack"
92+
"completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run dev\n\nDocumentation can be found at http://mpvue.com"
9293
};

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "vue-cli-template-webpack",
3-
"version": "2.0.0",
2+
"name": "mpvue-quickstart",
3+
"version": "1.0.0",
44
"license": "MIT",
5-
"description": "A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.",
5+
"description": "mpvue quickstart",
66
"scripts": {
77
"docs": "cd docs && gitbook serve",
88
"docs:deploy": "bash ./deploy-docs.sh"
99
},
1010
"devDependencies": {
11-
"vue-cli": "^2.8.1"
11+
"vue-cli": "^2.8.2"
1212
}
1313
}

template/.eslintrc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
sourceType: 'module'
88
},
99
env: {
10-
browser: true,
10+
browser: false,
11+
node: true,
12+
es6: true
1113
},
1214
{{#if_eq lintConfig "standard"}}
1315
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
@@ -51,5 +53,12 @@ module.exports = {
5153
{{/if_eq}}
5254
// allow debugger during development
5355
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
56+
},
57+
globals: {
58+
App: true,
59+
Page: true,
60+
wx: true,
61+
getApp: true,
62+
getPage: true
5463
}
5564
}

template/.postcssrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
"plugins": {
55
// to edit target browsers: use "browserslist" field in package.json
6-
"autoprefixer": {}
6+
"autoprefixer": {},
7+
"postcss-mpvue-wxss": {}
78
}
89
}

template/build/dev-server.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (!process.env.NODE_ENV) {
55
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
66
}
77

8-
var opn = require('opn')
8+
// var opn = require('opn')
99
var path = require('path')
1010
var express = require('express')
1111
var webpack = require('webpack')
@@ -25,22 +25,22 @@ var proxyTable = config.dev.proxyTable
2525
var app = express()
2626
var compiler = webpack(webpackConfig)
2727

28-
var devMiddleware = require('webpack-dev-middleware')(compiler, {
29-
publicPath: webpackConfig.output.publicPath,
30-
quiet: true
31-
})
28+
// var devMiddleware = require('webpack-dev-middleware')(compiler, {
29+
// publicPath: webpackConfig.output.publicPath,
30+
// quiet: true
31+
// })
3232

33-
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
34-
log: false,
35-
heartbeat: 2000
36-
})
33+
// var hotMiddleware = require('webpack-hot-middleware')(compiler, {
34+
// log: false,
35+
// heartbeat: 2000
36+
// })
3737
// force page reload when html-webpack-plugin template changes
38-
compiler.plugin('compilation', function (compilation) {
39-
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
40-
hotMiddleware.publish({ action: 'reload' })
41-
cb()
42-
})
43-
})
38+
// compiler.plugin('compilation', function (compilation) {
39+
// compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
40+
// hotMiddleware.publish({ action: 'reload' })
41+
// cb()
42+
// })
43+
// })
4444

4545
// proxy api requests
4646
Object.keys(proxyTable).forEach(function (context) {
@@ -55,11 +55,11 @@ Object.keys(proxyTable).forEach(function (context) {
5555
app.use(require('connect-history-api-fallback')())
5656

5757
// serve webpack bundle output
58-
app.use(devMiddleware)
58+
// app.use(devMiddleware)
5959

6060
// enable hot-reload and state-preserving
6161
// compilation error display
62-
app.use(hotMiddleware)
62+
// app.use(hotMiddleware)
6363

6464
// serve pure static assets
6565
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
@@ -72,18 +72,24 @@ var readyPromise = new Promise(resolve => {
7272
_resolve = resolve
7373
})
7474

75-
console.log('> Starting dev server...')
76-
devMiddleware.waitUntilValid(() => {
77-
console.log('> Listening at ' + uri + '\n')
78-
// when env is testing, don't need open it
79-
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
80-
opn(uri)
81-
}
82-
_resolve()
83-
})
75+
// console.log('> Starting dev server...')
76+
// devMiddleware.waitUntilValid(() => {
77+
// console.log('> Listening at ' + uri + '\n')
78+
// // when env is testing, don't need open it
79+
// if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
80+
// opn(uri)
81+
// }
82+
// _resolve()
83+
// })
8484

8585
var server = app.listen(port, 'localhost')
8686

87+
// for 小程序的文件保存机制
88+
require('webpack-dev-middleware-hard-disk')(compiler, {
89+
publicPath: webpackConfig.output.publicPath,
90+
quiet: true
91+
})
92+
8793
module.exports = {
8894
ready: readyPromise,
8995
close: () => {

template/build/utils.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ exports.cssLoaders = function (options) {
2020
}
2121
}
2222

23+
var postcssLoader = {
24+
loader: 'postcss-loader',
25+
options: {
26+
sourceMap: true
27+
}
28+
}
29+
30+
var px2rpxLoader = {
31+
loader: 'px2rpx-loader',
32+
options: {
33+
baseDpr: 1,
34+
rpxUnit: 0.5
35+
}
36+
}
37+
2338
// generate loader string to be used with extract text plugin
2439
function generateLoaders (loader, loaderOptions) {
25-
var loaders = [cssLoader]
40+
var loaders = [cssLoader, postcssLoader, px2rpxLoader]
2641
if (loader) {
2742
loaders.push({
2843
loader: loader + '-loader',

template/build/vue-loader.conf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var utils = require('./utils')
22
var config = require('../config')
3-
var isProduction = process.env.NODE_ENV === 'production'
3+
// var isProduction = process.env.NODE_ENV === 'production'
4+
// for mp
5+
var isProduction = true
46

57
module.exports = {
68
loaders: utils.cssLoaders({

0 commit comments

Comments
 (0)