├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── README.md ├── build ├── build.js ├── deploy.js ├── dev-client.js ├── dev-server.js ├── dist-server.js ├── serverRender.js ├── utils.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── App.vue ├── App1.vue ├── articleList.json ├── articlesRoutes.js ├── assets │ ├── logo.png │ ├── stylus │ │ ├── animation.styl │ │ ├── button.styl │ │ ├── flexGrid.styl │ │ ├── flexGridMobile.styl │ │ ├── flexGridNormal.styl │ │ ├── flexGridPad.styl │ │ ├── global.styl │ │ ├── layout.styl │ │ ├── main.styl │ │ ├── md.styl │ │ ├── mixins.styl │ │ ├── preinstall.styl │ │ ├── svg.styl │ │ ├── utils.styl │ │ └── variable.styl │ └── svg │ │ └── all.pug ├── components │ ├── Demo.vue │ ├── Feedback.vue │ ├── Hello.vue │ ├── Home.vue │ ├── article.vue │ ├── demo │ │ ├── DemoVuexState.vue │ │ └── FlexGrid.vue │ ├── feedback │ │ └── Loading.vue │ ├── home │ │ └── RepoInfo.vue │ └── templates │ │ ├── AppArticleList.vue │ │ ├── HomeHeader.vue │ │ ├── MainButton.vue │ │ └── User.vue ├── directives │ ├── index.js │ └── v-bgi.js ├── main.js ├── resources │ ├── auth.js │ ├── http.js │ └── resource.js ├── router.js ├── routes.js ├── services │ └── alloy_finger.js ├── store │ ├── index.js │ ├── modules │ │ ├── demo.js │ │ └── status.js │ └── types.js └── utils │ ├── device.js │ ├── fullScreen.js │ └── scroll.js ├── static ├── .gitkeep ├── favicon.ico └── img │ ├── demo │ ├── flex-container.png │ └── zxcyy.jpg │ └── logo.png └── test ├── e2e ├── custom-assertions │ └── elementCount.js ├── nightwatch.conf.js ├── runner.js └── specs │ └── test.js └── unit ├── .eslintrc ├── index.js ├── karma.conf.js └── specs └── Hello.spec.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-2"], 3 | "plugins": ["transform-runtime"], 4 | "comments": false 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 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 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: 'babel-eslint', 4 | parserOptions: { 5 | sourceType: 'module' 6 | }, 7 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 8 | extends: 'standard', 9 | // required to lint *.vue files 10 | plugins: [ 11 | 'html' 12 | ], 13 | // add your custom rules here 14 | 'rules': { 15 | // allow paren-less arrow functions 16 | 'arrow-parens': 0, 17 | // allow async-await 18 | 'generator-star-spacing': 0, 19 | // allow debugger during development 20 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log 5 | test/unit/coverage 6 | test/e2e/reports 7 | selenium-debug.log 8 | .deploy 9 | .deploy_coding 10 | 11 | # 文章 12 | src/md/articles/ 13 | src/articlesPreRender.js 14 | src/articleList.json 15 | src/articlesRoutes.js -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue2.0-demo 2 | 捣鼓捣鼓vue2.0 3 | 使用 Material 风格 4 | 后面会加入大量微动效 5 | 6 | # 环境 7 | nodejs >= v7.0 (当然,更新到最新也是极好的,可以享受最新功能) 8 | 9 | # 安装 10 | 克隆仓库到本地 11 | ``` 12 | git clone git@github.com:leenty/vue2.git 13 | ``` 14 | 安装依赖 15 | ``` 16 | npm i 17 | ``` 18 | 安装[命令行工具`lebo`](https://github.com/leenty/lebo) 19 | ``` 20 | npm i -g lebo 21 | ``` 22 | 创建文章目录 23 | ``` 24 | lebo article --mkdir 25 | # 简写 26 | lebo a -m 27 | ``` 28 | 创建文章 29 | ``` 30 | lebo article --create 'demo' 31 | # 简写 32 | lebo a -c 'demo' 33 | ``` 34 | 创建文章路由 35 | ``` 36 | lebo article --render 37 | # 简写 38 | lebo a -r 39 | ``` 40 | 41 | # 新建文章及路由生成 42 | ``` 43 | $ lebo -h 44 | Usage: cli [options] 45 | 46 | Options: 47 | -V, --version 查看版本号 48 | -h, --help 查看帮助 49 | 50 | Commands: 51 | article|a [options] 创建文章和创建文章路由 52 | init|i 创建项目(开发中) 53 | 54 | $ lebo article -h 55 | Usage: article|a [options] 56 | 创建文章和创建文章路由 57 | 58 | Options: 59 | -r, --render 生成文章路由 60 | -c, --create
生成名为
的文章 61 | -m, --mkdir 生成文章目录 62 | -h, --help 查看帮助 63 | ``` 64 | 65 | # 当前css规则 66 | ``` 67 | css命名使用 BEM+emmet 风格作为命名规范 68 | 69 | 约定[分类名称|模块名称][属性|组件名称]与[属性名]使用小写 70 | 约定[描述]与[状态]使用首字母大写 71 | [eg]: 72 | .[分类名称|模块名称]__[子分类|子模块]-[属性|组件名称][描述]--[属性值|状态] 73 | => .l-flexV--c 74 | => .b-base--Active 75 | => .fg-offset-12 76 | => .fg__pad-offset-12 77 | 78 | 1.约定 [分类名称|模块名称] 缩写: 79 | • .layout => .l- (布局部分) 80 | • .utils => .u- (工具部分) 81 | • .button => .b- (按钮部分) 82 | 83 | 2.约定通用 [属性] 缩写:(以emmet联想风格为缩写) 84 | • width => w 85 | • height => h 86 | • color => c 87 | • background => bg 88 | • margin => m 89 | • padding => p 90 | • border => bd 91 | 92 | 3.约定通用 [组件名称]:(这里不使用缩写, 93 | 因为组件名可以自定义,缩写易混淆,会增加记忆成本) 94 | • flex => flex (这里所指的是弹性盒子) 95 | 96 | 4.约定通用 [描述] 缩写:(以大写) 97 | • horizontal => H 98 | • vertical => V 99 | • normal => N 100 | 101 | 5.约定通用 [属性值] 缩写:(以属性前缀 '--' + emmet联想风格为缩写) 102 | • center => --c 103 | • middle => --m 104 | • space-around => --sa 105 | 106 | 6.约定通用 [状态] 缩写:(以属性前缀 '--' + 状态首字母大写, 107 | 这里不使用缩写,因为状态名可以自定义,缩写易混淆,会增加记忆成本) 108 | • active => --Active 109 | ``` -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | // https://github.com/shelljs/shelljs 2 | require('shelljs/global') 3 | env.NODE_ENV = 'production' 4 | 5 | var path = require('path') 6 | var config = require('../config') 7 | var ora = require('ora') 8 | var webpack = require('webpack') 9 | var webpackConfig = require('./webpack.prod.conf') 10 | 11 | console.log( 12 | ' Tip:\n' + 13 | ' Built files are meant to be served over an HTTP server.\n' + 14 | ' Opening index.html over file:// won\'t work.\n' 15 | ) 16 | 17 | var spinner = ora('building for production...') 18 | spinner.start() 19 | 20 | var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory) 21 | rm('-rf', assetsPath) 22 | mkdir('-p', assetsPath) 23 | cp('-R', 'static/*', assetsPath) 24 | 25 | webpack(webpackConfig, function (err, stats) { 26 | spinner.stop() 27 | if (err) throw err 28 | process.stdout.write(stats.toString({ 29 | colors: true, 30 | modules: false, 31 | children: false, 32 | chunks: false, 33 | chunkModules: false 34 | }) + '\n') 35 | }) 36 | -------------------------------------------------------------------------------- /build/deploy.js: -------------------------------------------------------------------------------- 1 | require('shelljs/global') 2 | let ora = require('ora') 3 | // var git = require("nodegit") 4 | var path = require('path') 5 | 6 | var argv = require('minimist')(process.argv.slice(2)) 7 | 8 | Date.prototype.format = function(fmt) { 9 | let o = { 10 | "M+" : this.getMonth()+1, 11 | "d+" : this.getDate(), 12 | "h+" : this.getHours(), 13 | "m+" : this.getMinutes(), 14 | "s+" : this.getSeconds(), 15 | "q+" : Math.floor((this.getMonth()+3)/3), 16 | "S" : this.getMilliseconds() 17 | } 18 | if(/(y+)/.test(fmt)) 19 | fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 20 | for(let k in o) 21 | if(new RegExp("("+ k +")").test(fmt)) 22 | fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? 23 | (o[k]) : 24 | (("00"+ o[k]).substr((""+ o[k]).length))) 25 | return fmt 26 | } 27 | 28 | const commitTime = new Date() 29 | const commitName = `deploy at ${commitTime.format("yyyy-MM-dd hh:mm:ss")}` 30 | 31 | const setDeploy = function () { 32 | let dir = '.deploy' 33 | let spinner = ora(`building and deploy at ${argv._.toString()} \n`) 34 | spinner.start() 35 | 36 | rm('-rf', `${dir}/*`) 37 | cp('-R', ['dist/*', dir]) 38 | cd(dir) 39 | exec('git add .') 40 | exec(`git cm -m "deploy at ${commitName}"`) 41 | // pushDeploy('master', 'git@git.coding.net:leenty/vue2.leenty.com.git') 42 | pushDeploy('gh-pages', 'git@github.com:leenty/vue2.git') 43 | 44 | // cd('..') 45 | // deploy() 46 | 47 | spinner.stop() 48 | console.log('\n') 49 | } 50 | setDeploy() 51 | 52 | function pushDeploy(branch, repository) { 53 | exec(`git push -u ${repository} HEAD:${branch} --force`) 54 | } 55 | 56 | // function deploy() { 57 | // let repo, index, oid, remote 58 | // const relativePath = '../.deploy/' 59 | // git.Repository.open('.deploy') 60 | // .then(repoResult => (repo = repoResult, repo.refreshIndex())) 61 | // .then(indexResult => (index = indexResult, repo.getStatus())) 62 | // .then(statuses => { 63 | // console.log('statuses.length', statuses.length) 64 | // if (statuses.length > 0) { 65 | // statuses.forEach(file => { 66 | // console.log(`addfile: ${path.join(__dirname, relativePath, file.path())}`) 67 | // index.addByPath(file.path()) 68 | // .then(() => index.write()) 69 | // .then(() => index.writeTree()) 70 | // .then(oidResult => (oid = oidResult, git.Reference.nameToId(repo, "HEAD"))) 71 | // .then(head => repo.getCommit(head)) 72 | // .then(parent => { 73 | // var author = git.Signature.default(repo) 74 | // return repo.createCommit("HEAD", author, author, commitName, oid, [parent]) 75 | // }) 76 | // .then(commitId => console.log(`\ncommitInfo:\n--commitId: ${commitId}\n--commitName: ${commitName}`)) 77 | // }) 78 | // } 79 | // }) 80 | // .then(() => git.Remote.delete(repo, 'origin')) 81 | // .then(() => git.Remote.create(repo, 'origin', 'git@git.coding.net:leenty/vue2.leenty.com.git')) 82 | // .then(remoteResult => { 83 | // remote = remoteResult 84 | // return remote.push( 85 | // ['refs/heads/master:refs/heads/master'], 86 | // { 87 | // callbacks: { 88 | // credentials: function(url, userName) { 89 | // return git.Cred.sshKeyFromAgent(userName); 90 | // } 91 | // } 92 | // } 93 | // )} 94 | // ) 95 | // .then(done => console.log('done! \n', done)) 96 | // .catch(err => console.log('error! \n', err)) 97 | // } 98 | 99 | // git push -u git@git.coding.net:leenty/vue2.leenty.com.git HEAD:master --force 100 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 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 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var opn = require('opn') 6 | var proxyMiddleware = require('http-proxy-middleware') 7 | var webpackConfig = process.env.NODE_ENV === 'testing' 8 | ? require('./webpack.prod.conf') 9 | : require('./webpack.dev.conf') 10 | 11 | // default port where dev server listens for incoming traffic 12 | var port = process.env.PORT || config.dev.port 13 | // Define HTTP proxies to your custom API backend 14 | // https://github.com/chimurai/http-proxy-middleware 15 | var proxyTable = config.dev.proxyTable 16 | 17 | var app = express() 18 | var compiler = webpack(webpackConfig) 19 | 20 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 21 | publicPath: webpackConfig.output.publicPath, 22 | stats: { 23 | colors: true, 24 | chunks: false 25 | } 26 | }) 27 | 28 | var hotMiddleware = require('webpack-hot-middleware')(compiler) 29 | // force page reload when html-webpack-plugin template changes 30 | compiler.plugin('compilation', function (compilation) { 31 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 32 | hotMiddleware.publish({ action: 'reload' }) 33 | cb() 34 | }) 35 | }) 36 | 37 | // proxy api requests 38 | Object.keys(proxyTable).forEach(function (context) { 39 | var options = proxyTable[context] 40 | if (typeof options === 'string') { 41 | options = { target: options } 42 | } 43 | app.use(proxyMiddleware(context, options)) 44 | }) 45 | 46 | // handle fallback for HTML5 history API 47 | app.use(require('connect-history-api-fallback')()) 48 | 49 | // serve webpack bundle output 50 | app.use(devMiddleware) 51 | 52 | // enable hot-reload and state-preserving 53 | // compilation error display 54 | app.use(hotMiddleware) 55 | 56 | // serve pure static assets 57 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 58 | app.use(staticPath, express.static('./static')) 59 | 60 | module.exports = app.listen(port, function (err) { 61 | if (err) { 62 | console.log(err) 63 | return 64 | } 65 | var uri = 'http://localhost:' + port 66 | console.log('Listening at ' + uri + '\n') 67 | opn(uri) 68 | }) 69 | -------------------------------------------------------------------------------- /build/dist-server.js: -------------------------------------------------------------------------------- 1 | require('shelljs/global') 2 | var path = require('path') 3 | var express = require('express') 4 | 5 | var app = express() 6 | 7 | app.use(express.static(path.join(__dirname, '../dist'))) 8 | 9 | app.listen('3111', function () { 10 | console.log('http://localhost:3111') 11 | exec('open http://localhost:3111') 12 | }) -------------------------------------------------------------------------------- /build/serverRender.js: -------------------------------------------------------------------------------- 1 | const Vue = require('vue') 2 | 3 | const renderer = require('vue-server-renderer').createRenderer() 4 | 5 | const vm = new Vue({ 6 | render (h) { 7 | return h('div', 'hello') 8 | } 9 | }) 10 | 11 | renderer.renderToString(vm, (err, html) => { 12 | console.log(html) // ->
hello
13 | }) -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | // generate loader string to be used with extract text plugin 15 | function generateLoaders (loaders) { 16 | var sourceLoader = loaders.map(function (loader) { 17 | var extraParamChar 18 | if (/\?/.test(loader)) { 19 | loader = loader.replace(/\?/, '-loader?') 20 | extraParamChar = '&' 21 | } else { 22 | loader = loader + '-loader' 23 | extraParamChar = '?' 24 | } 25 | return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '') 26 | }).join('!') 27 | 28 | if (options.extract) { 29 | return ExtractTextPlugin.extract('vue-style-loader', sourceLoader) 30 | } else { 31 | return ['vue-style-loader', sourceLoader].join('!') 32 | } 33 | } 34 | 35 | // http://vuejs.github.io/vue-loader/configurations/extract-css.html 36 | return { 37 | css: generateLoaders(['css']), 38 | postcss: generateLoaders(['css']), 39 | less: generateLoaders(['css', 'less']), 40 | sass: generateLoaders(['css', 'sass?indentedSyntax']), 41 | scss: generateLoaders(['css', 'sass']), 42 | stylus: generateLoaders(['css', 'stylus']), 43 | styl: generateLoaders(['css', 'stylus']) 44 | } 45 | } 46 | 47 | // Generate loaders for standalone style files (outside of .vue) 48 | exports.styleLoaders = function (options) { 49 | var output = [] 50 | var loaders = exports.cssLoaders(options) 51 | for (var extension in loaders) { 52 | var loader = loaders[extension] 53 | output.push({ 54 | test: new RegExp('\\.' + extension + '$'), 55 | loader: loader 56 | }) 57 | } 58 | return output 59 | } 60 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var utils = require('./utils') 4 | var projectRoot = path.resolve(__dirname, '../') 5 | // http://babeljs.io/docs/usage/polyfill/#top 6 | require('babel-polyfill') 7 | 8 | module.exports = { 9 | entry: { 10 | app: ['babel-polyfill', './src/main.js'] 11 | // app: './src/main.js' 12 | }, 13 | output: { 14 | path: config.build.assetsRoot, 15 | publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath, 16 | filename: '[name].js' 17 | }, 18 | resolve: { 19 | extensions: ['', '.js', '.vue'], 20 | fallback: [path.join(__dirname, '../node_modules')], 21 | alias: { 22 | 'vue': 'vue/dist/vue.common.js', 23 | 'src': path.resolve(__dirname, '../src'), 24 | 'assets': path.resolve(__dirname, '../src/assets'), 25 | 'components': path.resolve(__dirname, '../src/components'), 26 | 'config': path.resolve(__dirname, '../config') 27 | } 28 | }, 29 | resolveLoader: { 30 | fallback: [path.join(__dirname, '../node_modules')] 31 | }, 32 | module: { 33 | preLoaders: [ 34 | { 35 | test: /\.vue$/, 36 | loader: 'eslint', 37 | include: projectRoot, 38 | exclude: /node_modules/ 39 | }, 40 | { 41 | test: /\.js$/, 42 | loader: 'eslint', 43 | include: projectRoot, 44 | exclude: /node_modules/ 45 | } 46 | ], 47 | loaders: [ 48 | { 49 | test: /\.vue$/, 50 | loader: 'vue' 51 | }, 52 | { 53 | test: /\.js$/, 54 | loader: 'babel', 55 | include: projectRoot, 56 | exclude: /node_modules/ 57 | }, 58 | { 59 | test: /\.json$/, 60 | loader: 'json' 61 | }, 62 | { 63 | test: /\.md/, 64 | loader: 'vue-markdown-loader' 65 | }, 66 | { 67 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 68 | loader: 'url', 69 | query: { 70 | limit: 10000, 71 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 72 | } 73 | }, 74 | { 75 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 76 | loader: 'url', 77 | query: { 78 | limit: 10000, 79 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 80 | } 81 | } 82 | ] 83 | }, 84 | eslint: { 85 | formatter: require('eslint-friendly-formatter') 86 | }, 87 | vue: { 88 | loaders: utils.cssLoaders(), 89 | postcss: [ 90 | require('autoprefixer')({ 91 | browsers: ['last 2 versions'] 92 | }) 93 | ] 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var config = require('../config') 2 | var webpack = require('webpack') 3 | var merge = require('webpack-merge') 4 | var utils = require('./utils') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | 8 | // add hot-reload related code to entry chunks 9 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 10 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 11 | }) 12 | 13 | module.exports = merge(baseWebpackConfig, { 14 | module: { 15 | loaders: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 16 | }, 17 | // eval-source-map is faster for development 18 | devtool: '#eval-source-map', 19 | plugins: [ 20 | new webpack.DefinePlugin({ 21 | 'process.env': config.dev.env 22 | }), 23 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 24 | new webpack.optimize.OccurenceOrderPlugin(), 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }) 33 | ] 34 | }) 35 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var utils = require('./utils') 4 | var webpack = require('webpack') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var PrerenderSpaPlugin = require('prerender-spa-plugin') 10 | 11 | var env = process.env.NODE_ENV === 'testing' 12 | ? require('../config/test.env') 13 | : config.build.env 14 | 15 | var pages = ['/', '/article', '/demo', '/demo/vuex_state', '/demo/flexgrid' ] 16 | pages = pages.concat(require('../src/articlesPreRender.js')) 17 | 18 | var webpackConfig = merge(baseWebpackConfig, { 19 | module: { 20 | loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true }) 21 | }, 22 | devtool: config.build.productionSourceMap ? '#source-map' : false, 23 | output: { 24 | path: config.build.assetsRoot, 25 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 26 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 27 | }, 28 | vue: { 29 | loaders: utils.cssLoaders({ 30 | sourceMap: config.build.productionSourceMap, 31 | extract: true 32 | }) 33 | }, 34 | plugins: [ 35 | // http://vuejs.github.io/vue-loader/workflow/production.html 36 | new webpack.DefinePlugin({ 37 | 'process.env': env 38 | }), 39 | new webpack.optimize.UglifyJsPlugin({ 40 | compress: { 41 | warnings: false 42 | } 43 | }), 44 | new webpack.optimize.OccurenceOrderPlugin(), 45 | // extract css into its own file 46 | new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')), 47 | // generate dist index.html with correct asset hash for caching. 48 | // you can customize output by editing /index.html 49 | // see https://github.com/ampedandwired/html-webpack-plugin 50 | new HtmlWebpackPlugin({ 51 | filename: process.env.NODE_ENV === 'testing' 52 | ? 'index.html' 53 | : config.build.index, 54 | template: 'index.html', 55 | inject: true, 56 | minify: { 57 | removeComments: true, 58 | collapseWhitespace: true, 59 | removeAttributeQuotes: true 60 | // more options: 61 | // https://github.com/kangax/html-minifier#options-quick-reference 62 | }, 63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 64 | chunksSortMode: 'dependency' 65 | }), 66 | // split vendor js into its own file 67 | new webpack.optimize.CommonsChunkPlugin({ 68 | name: 'vendor', 69 | minChunks: function (module, count) { 70 | // any required modules inside node_modules are extracted to vendor 71 | return ( 72 | module.resource && 73 | /\.js$/.test(module.resource) && 74 | module.resource.indexOf( 75 | path.join(__dirname, '../node_modules') 76 | ) === 0 77 | ) 78 | } 79 | }), 80 | // extract webpack runtime and module manifest to its own file in order to 81 | // prevent vendor hash from being updated whenever app bundle is updated 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'manifest', 84 | chunks: ['vendor'] 85 | }), 86 | new PrerenderSpaPlugin( 87 | path.join(__dirname, '../dist'), 88 | pages 89 | // { 90 | // // captureAfterDocumentEvent: 'DOMContentLoaded', 91 | // // captureAfterElementExists: '.app', 92 | // captureAfterTime: 5000 93 | // // maxAttempts: 10, 94 | // // navigationLocked: true, 95 | // // phantomOptions: '--disk-cache=true', 96 | // // phantomPageSettings: { 97 | // // loadImages: true 98 | // // } 99 | // } 100 | ) 101 | ] 102 | }) 103 | 104 | if (config.build.productionGzip) { 105 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 106 | 107 | webpackConfig.plugins.push( 108 | new CompressionWebpackPlugin({ 109 | asset: '[path].gz[query]', 110 | algorithm: 'gzip', 111 | test: new RegExp( 112 | '\\.(' + 113 | config.build.productionGzipExtensions.join('|') + 114 | ')$' 115 | ), 116 | threshold: 10240, 117 | minRatio: 0.8 118 | }) 119 | ) 120 | } 121 | 122 | module.exports = webpackConfig 123 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: false, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'] 18 | }, 19 | dev: { 20 | env: require('./dev.env'), 21 | port: 8090, 22 | assetsSubDirectory: 'static', 23 | assetsPublicPath: '/', 24 | proxyTable: {}, 25 | // CSS Sourcemaps off by default because relative paths are "buggy" 26 | // with this option, according to the CSS-Loader README 27 | // (https://github.com/webpack/css-loader#sourcemaps) 28 | // In our experience, they generally work as expected, 29 | // just be aware of this issue when enabling this option. 30 | cssSourceMap: false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var devEnv = require('./dev.env') 3 | 4 | module.exports = merge(devEnv, { 5 | NODE_ENV: '"testing"' 6 | }) 7 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vue2.0-demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | 36 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue2.0-demo", 3 | "version": "1.0.0", 4 | "description": "vue2.0 and use material style", 5 | "author": "leenty ", 6 | "private": true, 7 | "scripts": { 8 | "deploy": "node build/deploy.js", 9 | "dev": "node build/dev-server.js", 10 | "article": "node build/new-article.js", 11 | "dist": "node build/dist-server.js", 12 | "build": "node build/build.js", 13 | "unit": "karma start test/unit/karma.conf.js --single-run", 14 | "e2e": "node test/e2e/runner.js", 15 | "test": "npm run unit && npm run e2e", 16 | "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" 17 | }, 18 | "dependencies": { 19 | "alloyfinger": "^0.1.3", 20 | "axios": "^0.15.3", 21 | "js-cookie": "^2.2.0", 22 | "vue": "^2.0.1", 23 | "vue-duoshuo": "^1.0.6", 24 | "vue-router": "^2.0.1", 25 | "vuex": "^2.0.0" 26 | }, 27 | "devDependencies": { 28 | "autoprefixer": "^6.4.0", 29 | "babel-core": "^6.0.0", 30 | "babel-eslint": "^7.0.0", 31 | "babel-loader": "^6.0.0", 32 | "babel-plugin-transform-runtime": "^6.0.0", 33 | "babel-polyfill": "^6.16.0", 34 | "babel-preset-es2015": "^6.0.0", 35 | "babel-preset-stage-2": "^6.0.0", 36 | "babel-register": "^6.0.0", 37 | "chai": "^3.5.0", 38 | "chromedriver": "^2.21.2", 39 | "connect-history-api-fallback": "^1.1.0", 40 | "cross-spawn": "^4.0.2", 41 | "css-loader": "^0.25.0", 42 | "eslint": "^3.7.1", 43 | "eslint-config-standard": "^6.1.0", 44 | "eslint-friendly-formatter": "^2.0.5", 45 | "eslint-loader": "^1.5.0", 46 | "eslint-plugin-html": "^1.3.0", 47 | "eslint-plugin-promise": "^3.5.0", 48 | "eslint-plugin-standard": "^2.0.1", 49 | "eventsource-polyfill": "^0.9.6", 50 | "express": "^4.13.3", 51 | "extract-text-webpack-plugin": "^1.0.1", 52 | "file-loader": "^0.9.0", 53 | "function-bind": "^1.0.2", 54 | "html-webpack-plugin": "^2.8.1", 55 | "http-proxy-middleware": "^0.17.2", 56 | "inject-loader": "^2.0.1", 57 | "isparta-loader": "^2.0.0", 58 | "json-loader": "^0.5.4", 59 | "karma": "^1.3.0", 60 | "karma-coverage": "^1.1.1", 61 | "karma-mocha": "^1.2.0", 62 | "karma-phantomjs-launcher": "^1.0.0", 63 | "karma-sinon-chai": "^1.2.0", 64 | "karma-sourcemap-loader": "^0.3.7", 65 | "karma-spec-reporter": "0.0.26", 66 | "karma-webpack": "^1.7.0", 67 | "lolex": "^1.4.0", 68 | "minimist": "^1.2.0", 69 | "mkdirp": "^0.5.1", 70 | "mocha": "^3.1.0", 71 | "nightwatch": "^0.9.8", 72 | "opn": "^4.0.2", 73 | "ora": "^0.3.0", 74 | "phantomjs-prebuilt": "^2.1.3", 75 | "prerender-spa-plugin": "^1.3.0", 76 | "pug": "^2.0.0-beta6", 77 | "selenium-server": "2.53.1", 78 | "shelljs": "^0.7.4", 79 | "sinon": "^1.17.3", 80 | "sinon-chai": "^2.8.0", 81 | "stylus": "^0.54.5", 82 | "stylus-loader": "^2.3.1", 83 | "url-loader": "^0.5.7", 84 | "vue-loader": "^9.4.0", 85 | "vue-markdown-loader": "^0.6.1", 86 | "vue-server-renderer": "^2.0.8", 87 | "vue-style-loader": "^1.0.0", 88 | "webpack": "^1.13.2", 89 | "webpack-dev-middleware": "^1.8.3", 90 | "webpack-hot-middleware": "^2.12.2", 91 | "webpack-merge": "^0.14.1" 92 | }, 93 | "engines": { 94 | "node": ">= 4.0.0", 95 | "npm": ">= 3.0.0" 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 56 | 57 | -------------------------------------------------------------------------------- /src/App1.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 34 | 35 | 65 | -------------------------------------------------------------------------------- /src/articleList.json: -------------------------------------------------------------------------------- 1 | [{"name":"vue2-1","title":"vue2.0一起在懵逼的海洋里越陷越深(一)","cover":"http://leenty.com/img/vue/vue2.0.png"},{"name":"vue2-2","title":"vue2.0一起在懵逼的海洋里越陷越深(二)","cover":"http://upload-images.jianshu.io/upload_images/2005796-3fc063c8fb0b1fba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300"},{"name":"vue2-3","title":"vue2.0一起在懵逼的海洋里越陷越深(三)","cover":"http://leenty.com/img/vue/chiss.jpg"},{"name":"vue2-4","title":"vue2.0一起在懵逼的海洋里越陷越深(四)","cover":"http://leenty.com/img/vue/flow.png"},{"name":"vue2-5","title":"vue2.0一起在懵逼的海洋里越陷越深(五)","cover":"http://leenty.com/img/vue/shangche.jpg"},{"name":"vue2-6","title":"vue2.0一起在懵逼的海洋里越陷越深(六)","cover":"http://www.leenty.com/img/vue/huaji_ld.jpg"}] -------------------------------------------------------------------------------- /src/articlesRoutes.js: -------------------------------------------------------------------------------- 1 | const articlesRouter = [{name: 'vue2-1', path: '/2016/10/21/vue2-1', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(一)'}, component: require('./md/articles/vue2-1.md')}, {name: 'vue2-2', path: '/2016/11/20/vue2-2', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(二)'}, component: require('./md/articles/vue2-2.md')}, {name: 'vue2-3', path: '/2016/11/27/vue2-3', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(三)'}, component: require('./md/articles/vue2-3.md')}, {name: 'vue2-4', path: '/2016/12/04/vue2-4', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(四)'}, component: require('./md/articles/vue2-4.md')}, {name: 'vue2-5', path: '/2016/12/11/vue2-5', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(五)'}, component: require('./md/articles/vue2-5.md')}, {name: 'vue2-6', path: '/2016/12/18/vue2-6', meta: {title: 'vue2.0一起在懵逼的海洋里越陷越深(六)'}, component: require('./md/articles/vue2-6.md')}] 2 | export default articlesRouter 3 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/src/assets/logo.png -------------------------------------------------------------------------------- /src/assets/stylus/animation.styl: -------------------------------------------------------------------------------- 1 | @keyframes jumpUp { 2 | 0% { 3 | transform translateY(0) 4 | } 5 | 50% { 6 | transform translateY(-50%) 7 | } 8 | 100% { 9 | transform translateY(0) 10 | } 11 | } 12 | 13 | @keyframes scaleOut { 14 | 100% { 15 | opacity 0 16 | transform scale(.6) 17 | } 18 | } 19 | @keyframes scaleIn { 20 | 0% { 21 | opacity 0 22 | transform scale(.6) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/assets/stylus/button.styl: -------------------------------------------------------------------------------- 1 | button 2 | border none 3 | outline none 4 | box-shadow none 5 | background none 6 | color currentColor 7 | padding 0 8 | cursor pointer 9 | vertical-align -30% 10 | 11 | .b-menu, 12 | .b-close, 13 | .b-top 14 | width 25px 15 | height 25px 16 | position relative 17 | &:before, 18 | &:after 19 | content ' ' 20 | position absolute 21 | background-color #fff 22 | display block 23 | width 100% 24 | height 3px 25 | left 0 26 | top 11px 27 | border-radius 3px 28 | transition all .5s cb-duang 29 | transform-origin 50% 50% 30 | 31 | .b-menu 32 | &:before 33 | transform translateY(-6px) 34 | &:after 35 | box-shadow 0 6px 0 0 #fff 36 | .b-close 37 | &:before 38 | transform rotateZ(45deg) translateY(0) 39 | &:after 40 | box-shadow 0 0 0 0 #fff 41 | transform rotateZ(135deg) translateY(0) 42 | .b-top 43 | &:before, 44 | &:after 45 | transform-origin 50% 50% 46 | top 15% 47 | left 15% 48 | width 70% 49 | &:before 50 | transform rotateZ(135deg) translate(50%, -25%) 51 | &:after 52 | box-shadow 0 0 0 0 #fff 53 | transform rotateZ(45deg) translate(50%, 25%) 54 | 55 | .b-svgBtn 56 | padding 5px 57 | background-color c-ff 58 | border-radius 50% 59 | color c-master 60 | box-sizing content-box 61 | border 1px solid c-master 62 | height 24px 63 | transition all .5s cb-duang 64 | // position relative 65 | // &:after 66 | // content ' ' 67 | // display block 68 | // width 5px 69 | // height @width 70 | // background-color c-master 71 | // border-radius 50% 72 | // position absolute 73 | // left 50% 74 | // top 50% 75 | // transform-origin center center 76 | // transform translate(-50%, -50%) 77 | svg 78 | border-radius 50% 79 | .b-svgBtn--Active 80 | background-color c-master 81 | color #fff 82 | .b-svgBtn--Pending 83 | animation jumpUp .4s infinite alternate 84 | -------------------------------------------------------------------------------- /src/assets/stylus/flexGrid.styl: -------------------------------------------------------------------------------- 1 | /*** grid ***/ 2 | 3 | fg-row(v) 4 | display flex 5 | if v == 'r' 6 | flex-flow row-reverse wrap 7 | else 8 | flex-flow row wrap 9 | fg-col(v) 10 | display flex 11 | if v == 'r' 12 | flex-flow column-reverse wrap 13 | else 14 | flex-flow column wrap 15 | 16 | fg-wrap(v) 17 | if v == 'no' 18 | flex-wrap nowrap 19 | else if v == 'r' 20 | flex-wrap wrap-reverse 21 | else 22 | flex-wrap wrap 23 | 24 | fg-auto() 25 | flex 0 0 auto 26 | fg-full() 27 | flex 1 1 auto 28 | fg-grid(items) 29 | flex 0 1 (items/24*100) % 30 | 31 | fg-jc(v) 32 | if v == 'sb' 33 | justify-content space-between 34 | if v == 'sa' 35 | justify-content space-around 36 | if v == 'c' 37 | justify-content center 38 | if v == 'fe' 39 | justify-content flex-end 40 | if v == 'fs' 41 | justify-content flex-start 42 | 43 | fg-ai(v) 44 | if v == 'st' 45 | align-items stretch 46 | if v == 'bl' 47 | align-items baseline 48 | if v == 'c' 49 | align-items center 50 | if v == 'fe' 51 | align-items flex-end 52 | if v == 'fs' 53 | align-items flex-start 54 | 55 | fg-order(o) 56 | order o 57 | 58 | fg-offset(items) 59 | margin-left (items/24*100) % 60 | 61 | /*** grid ***/ 62 | @import './flexGridNormal' 63 | 64 | // pad < 768px 65 | @import './flexGridPad' 66 | 67 | // mobile < 500px 68 | @import './flexGridMobile' 69 | -------------------------------------------------------------------------------- /src/assets/stylus/flexGridMobile.styl: -------------------------------------------------------------------------------- 1 | // mobile < 500px 2 | @media screen and (max-width: mobile) 3 | .fg__mb-row 4 | fg-row(null) 5 | .fg__mb-col 6 | fg-col(null) 7 | .fg__mb-row--r 8 | fg-row(r) 9 | .fg__mb-col--r 10 | fg-col(r) 11 | 12 | .fg__mb-wrap--no 13 | fg-wrap(no) 14 | .fg__mb-wrap--r 15 | fg-wrap(r) 16 | .fg__mb-wrap 17 | fg-wrap(null) 18 | 19 | .fg__mb-auto 20 | fg-auto() 21 | .fg__mb-full 22 | fg-full() 23 | 24 | .fg__mb-24 25 | fg-grid(24) 26 | .fg__mb-23 27 | fg-grid(23) 28 | .fg__mb-22 29 | fg-grid(22) 30 | .fg__mb-21 31 | fg-grid(21) 32 | .fg__mb-20 33 | fg-grid(20) 34 | .fg__mb-19 35 | fg-grid(19) 36 | .fg__mb-18 37 | fg-grid(18) 38 | .fg__mb-17 39 | fg-grid(17) 40 | .fg__mb-17 41 | fg-grid(17) 42 | .fg__mb-16 43 | fg-grid(16) 44 | .fg__mb-15 45 | fg-grid(15) 46 | .fg__mb-14 47 | fg-grid(14) 48 | .fg__mb-13 49 | fg-grid(13) 50 | .fg__mb-12 51 | fg-grid(12) 52 | .fg__mb-11 53 | fg-grid(11) 54 | .fg__mb-10 55 | fg-grid(10) 56 | .fg__mb-9 57 | fg-grid(9) 58 | .fg__mb-8 59 | fg-grid(8) 60 | .fg__mb-7 61 | fg-grid(7) 62 | .fg__mb-6 63 | fg-grid(6) 64 | .fg__mb-5 65 | fg-grid(5) 66 | .fg__mb-4 67 | fg-grid(4) 68 | .fg__mb-3 69 | fg-grid(3) 70 | .fg__mb-2 71 | fg-grid(2) 72 | .fg__mb-1 73 | fg-grid(1) 74 | 75 | .fg__mb-jc--sb 76 | fg-jc(sb) 77 | .fg__mb-jc--sa 78 | fg-jc(sa) 79 | .fg__mb-jc--c 80 | fg-jc(c) 81 | .fg__mb-jc--fe 82 | fg-jc(fe) 83 | .fg__mb-jc--fs 84 | fg-jc(fs) 85 | 86 | .fg__mb-ai--st 87 | fg-ai(st) 88 | .fg__mb-ai--bl 89 | fg-ai(bl) 90 | .fg__mb-ai--c 91 | fg-ai(c) 92 | .fg__mb-ai--fe 93 | fg-ai(fe) 94 | .fg__mb-ai--fs 95 | fg-ai(fs) 96 | 97 | .fg__mb-after-1 98 | fg-order(1) 99 | .fg__mb-before-1 100 | fg-order(-1) 101 | .fg__mb-after-0, 102 | .fg__mb-before-0 103 | fg-order(0) 104 | 105 | /*** offset ***/ 106 | .fg__mb-offset-24 107 | fg-offset(24) 108 | .fg__mb-offset-23 109 | fg-offset(23) 110 | .fg__mb-offset-22 111 | fg-offset(22) 112 | .fg__mb-offset-21 113 | fg-offset(21) 114 | .fg__mb-offset-20 115 | fg-offset(20) 116 | .fg__mb-offset-19 117 | fg-offset(19) 118 | .fg__mb-offset-18 119 | fg-offset(18) 120 | .fg__mb-offset-17 121 | fg-offset(17) 122 | .fg__mb-offset-17 123 | fg-offset(17) 124 | .fg__mb-offset-16 125 | fg-offset(16) 126 | .fg__mb-offset-15 127 | fg-offset(15) 128 | .fg__mb-offset-14 129 | fg-offset(14) 130 | .fg__mb-offset-13 131 | fg-offset(13) 132 | .fg__mb-offset-12 133 | fg-offset(12) 134 | .fg__mb-offset-11 135 | fg-offset(11) 136 | .fg__mb-offset-10 137 | fg-offset(10) 138 | .fg__mb-offset-9 139 | fg-offset(9) 140 | .fg__mb-offset-8 141 | fg-offset(8) 142 | .fg__mb-offset-7 143 | fg-offset(7) 144 | .fg__mb-offset-6 145 | fg-offset(6) 146 | .fg__mb-offset-5 147 | fg-offset(5) 148 | .fg__mb-offset-4 149 | fg-offset(4) 150 | .fg__mb-offset-3 151 | fg-offset(3) 152 | .fg__mb-offset-2 153 | fg-offset(2) 154 | .fg__mb-offset-1 155 | fg-offset(1) -------------------------------------------------------------------------------- /src/assets/stylus/flexGridNormal.styl: -------------------------------------------------------------------------------- 1 | .fg-row 2 | fg-row(null) 3 | .fg-col 4 | fg-col(null) 5 | .fg-row--r 6 | fg-row(r) 7 | .fg-col--r 8 | fg-col(r) 9 | 10 | .fg-wrap--no 11 | fg-wrap(no) 12 | .fg-wrap--r 13 | fg-wrap(r) 14 | .fg-wrap 15 | fg-wrap(null) 16 | 17 | .fg-auto 18 | fg-auto() 19 | .fg-full 20 | fg-full() 21 | 22 | .fg-24 23 | fg-grid(24) 24 | .fg-23 25 | fg-grid(23) 26 | .fg-22 27 | fg-grid(22) 28 | .fg-21 29 | fg-grid(21) 30 | .fg-20 31 | fg-grid(20) 32 | .fg-19 33 | fg-grid(19) 34 | .fg-18 35 | fg-grid(18) 36 | .fg-17 37 | fg-grid(17) 38 | .fg-17 39 | fg-grid(17) 40 | .fg-16 41 | fg-grid(16) 42 | .fg-15 43 | fg-grid(15) 44 | .fg-14 45 | fg-grid(14) 46 | .fg-13 47 | fg-grid(13) 48 | .fg-12 49 | fg-grid(12) 50 | .fg-11 51 | fg-grid(11) 52 | .fg-10 53 | fg-grid(10) 54 | .fg-9 55 | fg-grid(9) 56 | .fg-8 57 | fg-grid(8) 58 | .fg-7 59 | fg-grid(7) 60 | .fg-6 61 | fg-grid(6) 62 | .fg-5 63 | fg-grid(5) 64 | .fg-4 65 | fg-grid(4) 66 | .fg-3 67 | fg-grid(3) 68 | .fg-2 69 | fg-grid(2) 70 | .fg-1 71 | fg-grid(1) 72 | 73 | .fg-jc--sb 74 | fg-jc(sb) 75 | .fg-jc--sa 76 | fg-jc(sa) 77 | .fg-jc--c 78 | fg-jc(c) 79 | .fg-jc--fe 80 | fg-jc(fe) 81 | .fg-jc--fs 82 | fg-jc(fs) 83 | 84 | .fg-ai--st 85 | fg-ai(st) 86 | .fg-ai--bl 87 | fg-ai(bl) 88 | .fg-ai--c 89 | fg-ai(c) 90 | .fg-ai--fe 91 | fg-ai(fe) 92 | .fg-ai--fs 93 | fg-ai(fs) 94 | 95 | .fg-after-1 96 | fg-order(1) 97 | .fg-before-1 98 | fg-order(-1) 99 | .fg-after-0, 100 | .fg-before-0 101 | fg-order(0) 102 | 103 | /*** offset ***/ 104 | .fg-offset-24 105 | fg-offset(24) 106 | .fg-offset-23 107 | fg-offset(23) 108 | .fg-offset-22 109 | fg-offset(22) 110 | .fg-offset-21 111 | fg-offset(21) 112 | .fg-offset-20 113 | fg-offset(20) 114 | .fg-offset-19 115 | fg-offset(19) 116 | .fg-offset-18 117 | fg-offset(18) 118 | .fg-offset-17 119 | fg-offset(17) 120 | .fg-offset-17 121 | fg-offset(17) 122 | .fg-offset-16 123 | fg-offset(16) 124 | .fg-offset-15 125 | fg-offset(15) 126 | .fg-offset-14 127 | fg-offset(14) 128 | .fg-offset-13 129 | fg-offset(13) 130 | .fg-offset-12 131 | fg-offset(12) 132 | .fg-offset-11 133 | fg-offset(11) 134 | .fg-offset-10 135 | fg-offset(10) 136 | .fg-offset-9 137 | fg-offset(9) 138 | .fg-offset-8 139 | fg-offset(8) 140 | .fg-offset-7 141 | fg-offset(7) 142 | .fg-offset-6 143 | fg-offset(6) 144 | .fg-offset-5 145 | fg-offset(5) 146 | .fg-offset-4 147 | fg-offset(4) 148 | .fg-offset-3 149 | fg-offset(3) 150 | .fg-offset-2 151 | fg-offset(2) 152 | .fg-offset-1 153 | fg-offset(1) -------------------------------------------------------------------------------- /src/assets/stylus/flexGridPad.styl: -------------------------------------------------------------------------------- 1 | // pad < 768px 2 | @media screen and (max-width: pad) 3 | .fg__pad-row 4 | fg-row(null) 5 | .fg__pad-col 6 | fg-col(null) 7 | .fg__pad-row--r 8 | fg-row(r) 9 | .fg__pad-col--r 10 | fg-col(r) 11 | 12 | .fg__pad-wrap--no 13 | fg-wrap(no) 14 | .fg__pad-wrap--r 15 | fg-wrap(r) 16 | .fg__pad-wrap 17 | fg-wrap(null) 18 | 19 | .fg__pad-auto 20 | fg-auto() 21 | .fg__pad-full 22 | fg-full() 23 | 24 | .fg__pad-24 25 | fg-grid(24) 26 | .fg__pad-23 27 | fg-grid(23) 28 | .fg__pad-22 29 | fg-grid(22) 30 | .fg__pad-21 31 | fg-grid(21) 32 | .fg__pad-20 33 | fg-grid(20) 34 | .fg__pad-19 35 | fg-grid(19) 36 | .fg__pad-18 37 | fg-grid(18) 38 | .fg__pad-17 39 | fg-grid(17) 40 | .fg__pad-17 41 | fg-grid(17) 42 | .fg__pad-16 43 | fg-grid(16) 44 | .fg__pad-15 45 | fg-grid(15) 46 | .fg__pad-14 47 | fg-grid(14) 48 | .fg__pad-13 49 | fg-grid(13) 50 | .fg__pad-12 51 | fg-grid(12) 52 | .fg__pad-11 53 | fg-grid(11) 54 | .fg__pad-10 55 | fg-grid(10) 56 | .fg__pad-9 57 | fg-grid(9) 58 | .fg__pad-8 59 | fg-grid(8) 60 | .fg__pad-7 61 | fg-grid(7) 62 | .fg__pad-6 63 | fg-grid(6) 64 | .fg__pad-5 65 | fg-grid(5) 66 | .fg__pad-4 67 | fg-grid(4) 68 | .fg__pad-3 69 | fg-grid(3) 70 | .fg__pad-2 71 | fg-grid(2) 72 | .fg__pad-1 73 | fg-grid(1) 74 | 75 | .fg__pad-jc--sb 76 | fg-jc(sb) 77 | .fg__pad-jc--sa 78 | fg-jc(sa) 79 | .fg__pad-jc--c 80 | fg-jc(c) 81 | .fg__pad-jc--fe 82 | fg-jc(fe) 83 | .fg__pad-jc--fs 84 | fg-jc(fs) 85 | 86 | .fg__pad-ai--st 87 | fg-ai(st) 88 | .fg__pad-ai--bl 89 | fg-ai(bl) 90 | .fg__pad-ai--c 91 | fg-ai(c) 92 | .fg__pad-ai--fe 93 | fg-ai(fe) 94 | .fg__pad-ai--fs 95 | fg-ai(fs) 96 | 97 | .fg__pad-after-1 98 | fg-order(1) 99 | .fg__pad-before-1 100 | fg-order(-1) 101 | .fg__pad-after-0, 102 | .fg__pad-before-0 103 | fg-order(0) 104 | 105 | /*** offset ***/ 106 | .fg__pad-offset-24 107 | fg-offset(24) 108 | .fg__pad-offset-23 109 | fg-offset(23) 110 | .fg__pad-offset-22 111 | fg-offset(22) 112 | .fg__pad-offset-21 113 | fg-offset(21) 114 | .fg__pad-offset-20 115 | fg-offset(20) 116 | .fg__pad-offset-19 117 | fg-offset(19) 118 | .fg__pad-offset-18 119 | fg-offset(18) 120 | .fg__pad-offset-17 121 | fg-offset(17) 122 | .fg__pad-offset-17 123 | fg-offset(17) 124 | .fg__pad-offset-16 125 | fg-offset(16) 126 | .fg__pad-offset-15 127 | fg-offset(15) 128 | .fg__pad-offset-14 129 | fg-offset(14) 130 | .fg__pad-offset-13 131 | fg-offset(13) 132 | .fg__pad-offset-12 133 | fg-offset(12) 134 | .fg__pad-offset-11 135 | fg-offset(11) 136 | .fg__pad-offset-10 137 | fg-offset(10) 138 | .fg__pad-offset-9 139 | fg-offset(9) 140 | .fg__pad-offset-8 141 | fg-offset(8) 142 | .fg__pad-offset-7 143 | fg-offset(7) 144 | .fg__pad-offset-6 145 | fg-offset(6) 146 | .fg__pad-offset-5 147 | fg-offset(5) 148 | .fg__pad-offset-4 149 | fg-offset(4) 150 | .fg__pad-offset-3 151 | fg-offset(3) 152 | .fg__pad-offset-2 153 | fg-offset(2) 154 | .fg__pad-offset-1 155 | fg-offset(1) 156 | -------------------------------------------------------------------------------- /src/assets/stylus/global.styl: -------------------------------------------------------------------------------- 1 | body 2 | font-family -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,SimSun,sans-serif 3 | color c-text 4 | background-color c-bgc 5 | -------------------------------------------------------------------------------- /src/assets/stylus/layout.styl: -------------------------------------------------------------------------------- 1 | // flex 2 | flexH() 3 | display flex 4 | flex-flow row nowrap 5 | flexV() 6 | display flex 7 | flex-flow column nowrap 8 | .l-flexH--sa 9 | flexH() 10 | align-items center 11 | justify-content space-around 12 | .l-flexV--c 13 | flexV() 14 | align-items center 15 | justify-content center 16 | .l-flexH 17 | flexH() 18 | .l-flexV 19 | flexV() 20 | .l-flex--auto 21 | flex 0 0 auto 22 | .l-flex--full 23 | flex 1 1 100% 24 | 25 | // page 26 | .l-page--Full 27 | position fixed 28 | left 0 29 | top 0 30 | width 100% 31 | height 100% 32 | 33 | // padding 34 | .l-p10 35 | padding 10px 36 | .l-pH10 37 | padding-left 10px 38 | padding-right 10px 39 | .l-pt10 40 | padding-top 10px 41 | .l-pr10 42 | padding-right 10px 43 | .l-pl5 44 | padding-left 5px 45 | .l-pl10 46 | padding-left 10px 47 | 48 | // margin 49 | .l-m--None 50 | margin 0 51 | .l-mH--auto 52 | margin 0 auto 53 | .l-mH10 54 | margin-left 10px 55 | margin-right 10px 56 | .l-mt20 57 | margin-top 20px 58 | .l-mr10 59 | margin-right 10px 60 | .l-mb5 61 | margin-bottom 5px 62 | -------------------------------------------------------------------------------- /src/assets/stylus/main.styl: -------------------------------------------------------------------------------- 1 | @import './preinstall' 2 | @import './global' 3 | @import './svg' 4 | @import './flexGrid' 5 | @import './layout' 6 | @import './utils' 7 | @import './button' 8 | @import './md' 9 | @import './animation' 10 | 11 | /** 12 | * css命名使用 BEM+emmet 风格作为命名规范 13 | * 14 | * 约定[分类名称][属性|组件名称]与[属性名]使用小写 15 | * 约定[描述]与[状态]使用首字母大写 16 | * [eg]: 17 | * .[分类名称]-[属性|组件名称][描述]--[属性值|状态] 18 | * => .l-flexV--c 19 | * => .b-base--Active 20 | * => .l-pt10 21 | * 22 | * 1.约定 [分类名称] 缩写: 23 | * • .layout => .l- (布局部分) 24 | * • .utils => .u- (工具部分) 25 | * • .button => .b- (按钮部分) 26 | * 27 | * 2.约定通用 [属性] 缩写:(以emmet联想风格为缩写) 28 | * • width => w 29 | * • height => h 30 | * • color => c 31 | * • background => bg 32 | * • margin => m 33 | * • padding => p 34 | * • padding-top => pt 35 | * • border => bd 36 | * 37 | * 3.约定通用 [组件名称]:(这里不使用缩写, 38 | * 因为组件名可以自定义,缩写易混淆,会增加记忆成本) 39 | * • flex => flex (这里所指的是弹性盒子) 40 | * 41 | * 4.约定通用 [描述] 缩写:(以大写) 42 | * • horizontal => H 43 | * • vertical => V 44 | * • normal => N 45 | * 46 | * 5.约定通用 [属性值] 缩写:(以属性前缀 '--' + emmet联想风格为缩写) 47 | * • [特例]以属性值为px的(不带'--') eg: 50px => 50 48 | * • [特例]以属性值为十六进制颜色的 eg: #f6f6f6 => --f6 49 | * • [特例]以属性值为十六进制颜色的(无规律的不缩写) eg: #ff8733 => --ff8733 50 | * • [特例]以数字开头的属性值写法(除以上特例外不使用缩写)eg: 1em => 1em 51 | * • center => --c 52 | * • middle => --m 53 | * • space-around => --sa 54 | * 55 | * 6.约定通用 [状态] 缩写:(以属性前缀 '--' + 状态首字母大写, 56 | * 这里不使用缩写,因为状态名可以自定义,缩写易混淆,会增加记忆成本) 57 | * • active => --Active 58 | */ 59 | -------------------------------------------------------------------------------- /src/assets/stylus/md.styl: -------------------------------------------------------------------------------- 1 | .md-content 2 | img 3 | display block 4 | max-width 100% 5 | margin 20px 0 6 | a 7 | text-decoration none 8 | color c-master 9 | a:visited 10 | color #69a79a 11 | h1,h2,h3,h4,h5,h6 12 | padding-bottom .3em 13 | border-bottom 1px solid #dcdcdc 14 | p 15 | line-height 1.4em 16 | &:not(:first-child) 17 | text-indent 1em 18 | pre 19 | // color #ccdce1 20 | // background-color #212e35 21 | // border 1px solid #465d65 22 | // border-radius 5px 23 | color #525252 24 | background-color #f8f8f8 25 | overflow auto 26 | padding 25px 10px 15px 27 | position relative 28 | font-size 13px 29 | font-family 'Roboto Mono', Monaco, courier, monospace 30 | code:before, 31 | code:after 32 | position absolute 33 | top 5px 34 | content attr(des) 35 | left 1em 36 | display inline-block 37 | // color #4a626b 38 | color #ccc 39 | font-size 12px 40 | code:after 41 | left initial 42 | right 1em 43 | content attr(class) 44 | .hljs-function 45 | color #a87fc6 46 | .hljs-built_in 47 | color #dcb360 48 | .hljs-keyword 49 | color #eb4f6a 50 | .hljs-attr 51 | color #5477bf 52 | .hljs-literal 53 | color #cd775f 54 | .hljs-params 55 | color #da7c61 56 | .hljs-number 57 | color #3abf8e 58 | .hljs-string 59 | color #72bd31 60 | .hljs-title 61 | color #6d94db 62 | .hljs-comment, 63 | .md-comment 64 | // color #4a626b 65 | color #b3b3b3 66 | 67 | .hljs-selector-id 68 | color #a87fc6 69 | .hljs-selector-class 70 | color #dcb360 71 | .hljs-selector-tag 72 | color #da7c61 73 | .hljs-attribute 74 | color #5477bf 75 | 76 | .hljs-meta 77 | color #eb4f6a 78 | .hljs-tag 79 | color #33b2d8 80 | .hljs-name 81 | color #dc3b42 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/assets/stylus/mixins.styl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/src/assets/stylus/mixins.styl -------------------------------------------------------------------------------- /src/assets/stylus/preinstall.styl: -------------------------------------------------------------------------------- 1 | @import './variable' 2 | @import './mixins' -------------------------------------------------------------------------------- /src/assets/stylus/svg.styl: -------------------------------------------------------------------------------- 1 | // svg 2 | // vertical-align middle 3 | // color currentColor 4 | svg 5 | width 24px 6 | height 24px 7 | // .svg__home, 8 | // .svg__article 9 | // width 20px 10 | // height 20px 11 | 12 | // .svg__code 13 | // width 22px 14 | // height 20px 15 | -------------------------------------------------------------------------------- /src/assets/stylus/utils.styl: -------------------------------------------------------------------------------- 1 | // font-size 2 | .u-fs12 3 | font-size 12px 4 | .u-fs14 5 | font-size 14px 6 | .u-fs16 7 | font-size 16px 8 | .u-fs18 9 | font-size 18px 10 | 11 | // font-color 12 | .u-c--9e 13 | color c-9e 14 | 15 | /*** link ***/ 16 | .u-link 17 | text-decoration none 18 | color c-master 19 | .u-link__inherit 20 | text-decoration none 21 | color currentColor 22 | .u-link--Active 23 | color c-master 24 | 25 | /*** ul ***/ 26 | .u-ul--Reset 27 | list-style-type none 28 | padding-left 0 29 | 30 | // borderBox 31 | .u-borderBox 32 | box-sizing border-box 33 | 34 | /*** clearfix ***/ 35 | .u-clearfix:after, 36 | .u-clearfix:before 37 | display table 38 | content " " 39 | .u-clearfix:after 40 | clear both 41 | 42 | /*** box-shadow ***/ 43 | .u-boxShadow 44 | box-shadow 0px 2px 5px 0px rgba(0,0,0,0.3) 45 | 46 | // z-index 47 | .u-zIndex10 48 | z-index 10 49 | .u-zIndex50 50 | z-index 50 51 | 52 | // vertical-align 53 | .u-va--m 54 | vertical-align middle 55 | .u-va--tb 56 | vertical-align text-bottom 57 | 58 | // vertical-align 59 | .u-ta--c 60 | text-align center 61 | .u-ta--r 62 | text-align right 63 | .u-ta--l 64 | text-align left 65 | 66 | // background 67 | .u-bgi--Center 68 | background-size cover 69 | background-position center center 70 | background-repeat no-repeat 71 | -------------------------------------------------------------------------------- /src/assets/stylus/variable.styl: -------------------------------------------------------------------------------- 1 | /*** size ***/ 2 | max-width = 1000px 3 | 4 | /*** grid ***/ 5 | min = 320px // -∞ ~ 320px 6 | mobile = 500px // 320px ~ 500px 7 | pad = 768px // 768px ~ 992px 8 | laptop = 992px // 992px ~ 1200px 9 | pc = 1200px // 1200px ~ +∞ 10 | 11 | /*** colors ***/ 12 | // c-master = #6badf9 13 | c-master = #1abc9c 14 | c-lesser = #474747 15 | c-text = #34495e 16 | c-bgc = #edeef0 17 | // c-bgc = #000 18 | 19 | c-ff = #fff 20 | c-9e = #9e9e9e 21 | 22 | // size 23 | s-sideBar = 200px 24 | 25 | // cubic-bezier 26 | cb-duang = cubic-bezier(0.66, 0.1, 0.38, 1.45) 27 | -------------------------------------------------------------------------------- /src/assets/svg/all.pug: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/components/Demo.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 34 | 35 | -------------------------------------------------------------------------------- /src/components/Feedback.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 13 | 14 | -------------------------------------------------------------------------------- /src/components/Hello.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 16 | 17 | 18 | 23 | -------------------------------------------------------------------------------- /src/components/Home.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 21 | 22 | 24 | -------------------------------------------------------------------------------- /src/components/article.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 40 | 41 | 65 | -------------------------------------------------------------------------------- /src/components/demo/DemoVuexState.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 59 | 60 | -------------------------------------------------------------------------------- /src/components/demo/FlexGrid.vue: -------------------------------------------------------------------------------- 1 | 244 | 245 | 253 | 254 | -------------------------------------------------------------------------------- /src/components/feedback/Loading.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 14 | 15 | -------------------------------------------------------------------------------- /src/components/home/RepoInfo.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 51 | 52 | 54 | -------------------------------------------------------------------------------- /src/components/templates/AppArticleList.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 53 | 54 | 88 | 89 | -------------------------------------------------------------------------------- /src/components/templates/HomeHeader.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 74 | 75 | 159 | -------------------------------------------------------------------------------- /src/components/templates/MainButton.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 45 | 46 | -------------------------------------------------------------------------------- /src/components/templates/User.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 42 | 43 | 91 | -------------------------------------------------------------------------------- /src/directives/index.js: -------------------------------------------------------------------------------- 1 | import bgi from './v-bgi' 2 | 3 | const directives = { 4 | bgi 5 | } 6 | 7 | export default directives 8 | -------------------------------------------------------------------------------- /src/directives/v-bgi.js: -------------------------------------------------------------------------------- 1 | function bgi (el, binding) { 2 | el.style.backgroundImage = `url(${binding.value})` 3 | } 4 | const directive = { 5 | bind: bgi, 6 | update: bgi, 7 | unbind: bgi 8 | } 9 | 10 | export default directive 11 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | // import promise from 'es6-promise' 4 | import Vue from 'vue' 5 | import router from './router' 6 | import store from './store' 7 | 8 | import App from './App.vue' 9 | import directives from './directives' 10 | import AlloyFingerVue from './services/alloy_finger' 11 | Vue.use(AlloyFingerVue) 12 | 13 | for (let key in directives) { 14 | Vue.directive(key, directives[key]) 15 | } 16 | 17 | /* eslint-disable no-new */ 18 | new Vue({ 19 | router, 20 | // el: '#app', 21 | store, 22 | render: h => h(App) 23 | }).$mount('.app') 24 | 25 | console.log('\n %c leenty blog %c http://leenty.com \n\n', 'color: #fff; background: #1abc9c; padding:5px 0;border-radius: 5px 0 0 5px;', 'color: #34495e;background: #edeef0; padding:5px 0;border-radius: 0 5px 5px 0;text-decoration:none;') 26 | -------------------------------------------------------------------------------- /src/resources/auth.js: -------------------------------------------------------------------------------- 1 | import Cookies from 'js-cookie' 2 | 3 | export default { 4 | token: Cookies.get('token') || '', 5 | authenticated: () => !!Cookies.get('token'), 6 | setToken: token => { 7 | return Cookies.set('token', token, { expires: 1 }) 8 | }, 9 | removeToken: () => { 10 | Cookies.remove('token') 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/resources/http.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import auth from './auth' 3 | 4 | const instance = axios.create({ 5 | baseURL: 'http://192.168.141.17:8889/', 6 | // baseURL: 'http://api.leenty.com/' 7 | timeout: 1000 8 | }) 9 | 10 | instance.interceptors.request.use(config => { 11 | config.headers = { 12 | 'Content-Type': 'application/json' 13 | // 'Content-Type': 'application/x-www-form-urlencoded' 14 | } 15 | return config 16 | }, Promise.reject) 17 | 18 | instance.interceptors.response.use(({data}) => { 19 | if (data.success && data.token) { 20 | auth.setToken(data.token) 21 | } 22 | return data 23 | }, Promise.reject) 24 | 25 | const makeResource = function (url, baseData = {}) { 26 | const resuorce = function (methods, resData = {}) { 27 | const data = Object.assign({}, baseData, resData) 28 | // 替换参数 29 | url = url.replace(/:([A-z]+)/g, (str, p1) => data[p1]) 30 | return instance[methods](url, data) 31 | } 32 | return { 33 | get get () { 34 | return resuorce.bind(this, 'get') 35 | }, 36 | get post () { 37 | return resuorce.bind(this, 'post') 38 | }, 39 | get put () { 40 | return resuorce.bind(this, 'put') 41 | }, 42 | get delete () { 43 | return resuorce.bind(this, 'delete') 44 | } 45 | } 46 | } 47 | 48 | export default makeResource 49 | -------------------------------------------------------------------------------- /src/resources/resource.js: -------------------------------------------------------------------------------- 1 | import makeResource from './http' 2 | 3 | export const user = makeResource('/auth/user') 4 | export const userInfo = makeResource('/auth/user/:id') 5 | export const comment = makeResource('/api/comment') 6 | -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | import routes from './routes' 4 | import store from './store' 5 | 6 | const title = 'leenty blog Demo' 7 | 8 | Vue.use(VueRouter) 9 | 10 | /* eslint-disable no-new */ 11 | const router = new VueRouter({ 12 | mode: 'history', 13 | // mode: 'hash', 14 | linkActiveClass: 'u-link--Active', 15 | // base: '/app/', 16 | routes 17 | }) 18 | 19 | router.beforeEach((to, from, next) => { 20 | let titleStr = '' 21 | // to.matched.reverse().forEach((match, k) => { 22 | // titleStr += `${k > 0 ? '- ' : ''}${match.meta.title} ` 23 | // }) 24 | // tips: 直接翻转数组会导致路由嵌套位置的翻转 25 | if (to.name !== 'Home') { 26 | for (let i = to.matched.length - 1; i >= 0; i--) { 27 | titleStr += `${to.matched[i].meta.title} - ` 28 | } 29 | } 30 | titleStr += title 31 | document.title = titleStr 32 | store.dispatch('updateAppStatus', false) 33 | next() 34 | }) 35 | 36 | router.afterEach((route) => { 37 | store.dispatch('updateAppStatus', true) 38 | }) 39 | 40 | export default router 41 | -------------------------------------------------------------------------------- /src/routes.js: -------------------------------------------------------------------------------- 1 | // import Home from './components/Home.vue' 2 | // import Article from './components/Article.vue' 3 | // import Demo from './components/Demo.vue' 4 | // import DemoVuexState from './components/DemoVuexState.vue' 5 | 6 | import articles from './articlesRoutes.js' 7 | 8 | const routes = [ 9 | { 10 | name: 'Home', 11 | path: '/', 12 | meta: { 13 | title: 'home' 14 | }, 15 | component: require('./components/Home.vue') 16 | }, 17 | { 18 | name: 'Article', 19 | path: '/article', 20 | meta: { 21 | title: 'article' 22 | }, 23 | component: require('./components/Article.vue'), 24 | children: articles 25 | }, 26 | { 27 | name: 'Demo', 28 | path: '/demo', 29 | meta: { 30 | title: 'demo' 31 | }, 32 | component: require('./components/Demo.vue'), 33 | children: [ 34 | { 35 | name: 'DemoVuexState', 36 | path: 'vuex_state', 37 | meta: { 38 | title: 'vuex演示' 39 | }, 40 | component: require('./components/demo/DemoVuexState.vue') 41 | }, 42 | { 43 | name: 'FlexGrid', 44 | path: 'flexgrid', 45 | meta: { 46 | title: 'flexGrid' 47 | }, 48 | component: require('./components/demo/FlexGrid.vue') 49 | } 50 | ] 51 | } 52 | ] 53 | 54 | export default routes 55 | -------------------------------------------------------------------------------- /src/services/alloy_finger.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | const AlloyFingerPlugin = { 3 | install: function (Vue, options) { 4 | options = options || {} 5 | var AlloyFinger = window.AlloyFinger || options.AlloyFinger || require('alloyfinger') 6 | var isVue2 = !!(Vue.version.substr(0, 1) === '2') 7 | 8 | if (!AlloyFinger) { 9 | throw new Error('you need include the AlloyFinger!') 10 | } 11 | 12 | var EVENTMAP = { 13 | 'touch-start': 'touchStart', 14 | 'touch-move': 'touchMove', 15 | 'touch-end': 'touchEnd', 16 | 'touch-cancel': 'touchCancel', 17 | 'multipoint-start': 'multipointStart', 18 | 'multipoint-end': 'multipointEnd', 19 | 'tap': 'tap', 20 | 'double-tap': 'doubleTap', 21 | 'long-tap': 'longTap', 22 | 'single-tap': 'singleTap', 23 | 'rotate': 'rotate', 24 | 'pinch': 'pinch', 25 | 'press-move': 'pressMove', 26 | 'swipe': 'swipe' 27 | } 28 | 29 | var CACHE = [] 30 | 31 | var directiveOpts = {} 32 | 33 | // get the index for elem in CACHE 34 | var getElemCacheIndex = function (elem) { 35 | for (var i = 0, len = CACHE.length; i < len; i++) { 36 | if (CACHE[i].elem === elem) { 37 | return i 38 | } 39 | } 40 | 41 | return null 42 | } 43 | 44 | // do on or off handler 45 | var doOnOrOff = function (cacheObj, options) { 46 | var eventName = options.eventName 47 | var elem = options.elem 48 | var func = options.func 49 | var oldFunc = options.oldFunc 50 | 51 | if (cacheObj && cacheObj.alloyFinger) { 52 | if (cacheObj.alloyFinger.off && oldFunc) cacheObj.alloyFinger.off(eventName, oldFunc) 53 | if (cacheObj.alloyFinger.on && func) cacheObj.alloyFinger.on(eventName, func) 54 | } else { 55 | options = {} 56 | options[eventName] = func 57 | 58 | CACHE.push({ 59 | elem: elem, 60 | alloyFinger: new AlloyFinger(elem, options) 61 | }) 62 | } 63 | } 64 | 65 | // for bind the event 66 | var doBindEvent = function (elem, binding) { 67 | // console.log(binding) 68 | var func = binding.value 69 | var oldFunc = binding.oldValue 70 | var eventName = binding.arg 71 | 72 | eventName = EVENTMAP[eventName] 73 | 74 | var cacheObj = CACHE[getElemCacheIndex(elem)] 75 | 76 | doOnOrOff(cacheObj, { 77 | elem: elem, 78 | func: func, 79 | oldFunc: oldFunc, 80 | eventName: eventName 81 | }) 82 | } 83 | 84 | // for bind the event 85 | var doUnbindEvent = function (elem) { 86 | var index = getElemCacheIndex(elem) 87 | 88 | if (!isNaN(index)) { 89 | CACHE.splice(index, 1) 90 | } 91 | } 92 | 93 | if (isVue2) { 94 | directiveOpts = { 95 | bind: doBindEvent, 96 | update: doBindEvent, 97 | unbind: doUnbindEvent 98 | } 99 | } else { 100 | // vue1.xx 101 | directiveOpts = { 102 | update: function (newValue, oldValue) { 103 | var binding = { 104 | value: newValue, 105 | arg: this.arg 106 | } 107 | 108 | var elem = this.el 109 | 110 | doBindEvent.call(this, elem, binding) 111 | }, 112 | unbind: function () { 113 | var elem = this.el 114 | 115 | doUnbindEvent.call(this, elem) 116 | } 117 | } 118 | } 119 | 120 | // definition 121 | Vue.directive('finger', directiveOpts) 122 | } 123 | } 124 | // export 125 | if (typeof module !== 'undefined' && typeof exports === 'object') { 126 | module.exports = AlloyFingerPlugin 127 | } else { 128 | window.AlloyFingerVue = AlloyFingerPlugin 129 | } 130 | })() 131 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | // import * as actions from './actions' 4 | // import * as getters from './getters' 5 | 6 | import status from './modules/status' 7 | import demo from './modules/demo' 8 | // import createLogger from '../../../src/plugins/logger' 9 | 10 | Vue.use(Vuex) 11 | 12 | const debug = process.env.NODE_ENV !== 'production' 13 | 14 | export default new Vuex.Store({ 15 | // actions, 16 | // getters, 17 | modules: { 18 | status, 19 | demo 20 | }, 21 | strict: debug 22 | // plugins: debug ? [createLogger()] : [] 23 | // plugins: middlewares 24 | }) 25 | -------------------------------------------------------------------------------- /src/store/modules/demo.js: -------------------------------------------------------------------------------- 1 | import * as types from '../types' 2 | 3 | const state = { 4 | demoFollow: false, 5 | demoFollowPending: false 6 | } 7 | 8 | const getters = { 9 | demoFollowStatus: state => state.demoFollow ? '已关注' : '未关注' 10 | } 11 | 12 | const mutations = { 13 | [types.DEMO__VUEX_FOLLOW] (state, status = NaN) { 14 | state.demoFollow = isNaN(status) ? !state.demoFollow : status 15 | }, 16 | [types.DEMO__VUEX_FOLLOW_PENDING] (state, status = NaN) { 17 | state.demoFollowPending = isNaN(status) ? !state.demoFollowPending : status 18 | } 19 | } 20 | 21 | const actions = { 22 | demoFollowAjax ({commit}, status) { 23 | commit(types.DEMO__VUEX_FOLLOW_PENDING) 24 | setTimeout(() => { 25 | commit(types.DEMO__VUEX_FOLLOW_PENDING) 26 | commit(types.DEMO__VUEX_FOLLOW, status) 27 | }, 2000) 28 | } 29 | } 30 | 31 | export default { 32 | state, 33 | getters, 34 | actions, 35 | mutations 36 | } 37 | -------------------------------------------------------------------------------- /src/store/modules/status.js: -------------------------------------------------------------------------------- 1 | import * as types from '../types' 2 | 3 | import getScrollData from 'src/utils/scroll' 4 | import * as device from 'src/utils/device' 5 | 6 | const state = { 7 | sideBar: false, 8 | scroll: { 9 | scrollTop: 0, 10 | scrollHeight: 0, 11 | windowHeight: 0, 12 | scrollBottom: 0 13 | }, 14 | scrollDirection: true, // down: true | up: false 15 | navShrink: false, 16 | appReady: true, 17 | device: { 18 | width: device.deviceWidth(), 19 | height: device.deviceHeight(), 20 | isPc: device.isPc(), 21 | browserType: device.browserType(), 22 | isWx: device.isWechatAgent 23 | } 24 | } 25 | 26 | const getters = { 27 | // sideBar: ({status}) => status.sideBar 28 | // tips: 上面这种方法是错误的。这里的getters传入进来的不是state的根对象, 29 | // 而是当前的state对象,在这里也就相当于是state = state.status 30 | // 所以可以放心的用state 31 | sideBar: state => state.sideBar, 32 | scrollDirection: state => state.scrollDirection, 33 | navShrink: state => state.navShrink, 34 | appReady: state => state.appReady, 35 | device: state => state.device 36 | } 37 | 38 | const mutations = { 39 | [types.ARTICLE_LIST] (state) { 40 | state.sideBar = !state.sideBar 41 | }, 42 | [types.SCROLLDATA] (state, scrollObj) { 43 | state.scrollDirection = scrollObj.scrollTop > state.scroll.scrollTop 44 | if (scrollObj.scrollTop > 210) { 45 | state.navShrink = true 46 | } else if (scrollObj.scrollTop < 50) { 47 | state.navShrink = false 48 | } 49 | state.scroll = scrollObj 50 | }, 51 | [types.SCROLLTOP] () { 52 | document.querySelector('.app__content').scrollTop = 0 53 | }, 54 | [types.APPREADY] (state, bool) { 55 | state.appReady = bool 56 | }, 57 | [types.DEVICE] (state, device) { 58 | state.device = device 59 | } 60 | } 61 | 62 | const actions = { 63 | sideBarSwitch ({ commit }) { 64 | commit(types.ARTICLE_LIST) 65 | }, 66 | pushScrollData ({ commit }) { 67 | commit(types.SCROLLDATA, getScrollData(), { silent: true }) 68 | }, 69 | scollTop ({ commit }) { 70 | commit(types.SCROLLTOP) 71 | }, 72 | updateAppStatus ({ commit }, status) { 73 | commit(types.APPREADY, status) 74 | }, 75 | device ({ commit }) { 76 | commit(types.DEVICE, { 77 | width: device.deviceWidth(), 78 | height: device.deviceHeight(), 79 | isPc: device.isPc(), 80 | browserType: device.browserType(), 81 | isWx: device.isWechatAgent 82 | }) 83 | } 84 | } 85 | 86 | export default { 87 | state, 88 | getters, 89 | actions, 90 | mutations 91 | } 92 | -------------------------------------------------------------------------------- /src/store/types.js: -------------------------------------------------------------------------------- 1 | export const ARTICLE_LIST = 'ARTICLE_LIST' 2 | export const ARTICLE_LIST_SWITCH = 'ARTICLE_LIST_SWITCH' 3 | export const SCROLLDATA = 'SCROLLDATA' 4 | export const SCROLLTOP = 'SCROLLTOP' 5 | export const APPREADY = 'APPREADY' 6 | export const DEVICE = 'DEVICE' 7 | 8 | // demo 9 | export const DEMO__VUEX_FOLLOW = 'DEMO__VUEX_FOLLOW' 10 | export const DEMO__VUEX_FOLLOW_PENDING = 'DEMO__VUEX_FOLLOW_PENDING' 11 | -------------------------------------------------------------------------------- /src/utils/device.js: -------------------------------------------------------------------------------- 1 | var userAgent = navigator.userAgent 2 | export const isPc = function () { 3 | // var userAgent = navigator.userAgent 4 | var Agents = ['Android', 'iPhone', 5 | 'SymbianOS', 'Windows Phone', 6 | 'iPad', 'iPod'] 7 | var flag = true 8 | Agents.forEach(function (v) { 9 | if (userAgent.indexOf(v) > 0) { 10 | flag = false 11 | return false 12 | } 13 | }) 14 | return flag 15 | } 16 | 17 | export const browserType = function () { 18 | var isOpera = userAgent.indexOf('Opera') > -1 19 | if (isOpera) { 20 | return 'Opera' 21 | } 22 | if (userAgent.indexOf('Firefox') > -1) { 23 | return 'Firefox' 24 | } 25 | if (userAgent.indexOf('Chrome') > -1) { 26 | return 'Chrome' 27 | } 28 | if (userAgent.indexOf('Safari') > -1) { 29 | return 'Safari' 30 | } 31 | if (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 && !isOpera) { 32 | return 'IE' 33 | } 34 | } 35 | 36 | export const isWechatAgent = userAgent.indexOf('MicroMessenger') >= 0 37 | 38 | export const deviceWidth = () => window.innerWidth 39 | 40 | export const deviceHeight = () => window.innerHeight 41 | -------------------------------------------------------------------------------- /src/utils/fullScreen.js: -------------------------------------------------------------------------------- 1 | const fullScreen = function () { 2 | var docElm = document.documentElement 3 | if (docElm.requestFullscreen) { 4 | // W3C 5 | docElm.requestFullscreen() 6 | } else if (docElm.mozRequestFullScreen) { 7 | // FireFox 8 | docElm.mozRequestFullScreen() 9 | } else if (docElm.webkitRequestFullScreen) { 10 | // Chrome等 11 | console.log('test') 12 | docElm.webkitRequestFullScreen() 13 | } else if (docElm.msRequestFullscreen) { 14 | docElm.msRequestFullscreen() 15 | } 16 | } 17 | export default fullScreen 18 | -------------------------------------------------------------------------------- /src/utils/scroll.js: -------------------------------------------------------------------------------- 1 | const selector = '.app__content' 2 | 3 | // 滚动条在Y轴上的滚动距离 4 | function getScrollTop (scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0) { 5 | scrollTop = document.querySelector(selector).scrollTop 6 | return scrollTop 7 | } 8 | // 文档的总高度 9 | function getScrollHeight (scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0) { 10 | scrollHeight = document.querySelector(selector).scrollHeight 11 | return scrollHeight 12 | } 13 | // 浏览器视口的高度 14 | function getWindowHeight (windowHeight = 0) { 15 | if (document.compatMode === 'CSS1Compat') { 16 | windowHeight = document.documentElement.clientHeight 17 | } else { 18 | windowHeight = document.body.clientHeight 19 | } 20 | return windowHeight 21 | } 22 | 23 | const getScrollData = function () { 24 | let scrollTop = getScrollTop() 25 | let scrollHeight = getScrollHeight() 26 | let windowHeight = getWindowHeight() 27 | return { 28 | scrollTop, 29 | scrollHeight, 30 | windowHeight, 31 | scrollBottom: scrollHeight - scrollTop - windowHeight 32 | } 33 | } 34 | 35 | export default getScrollData 36 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/static/.gitkeep -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/static/favicon.ico -------------------------------------------------------------------------------- /static/img/demo/flex-container.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/static/img/demo/flex-container.png -------------------------------------------------------------------------------- /static/img/demo/zxcyy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/static/img/demo/zxcyy.jpg -------------------------------------------------------------------------------- /static/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leenty/vue2/ef7ac1a551931e0e5ef7df85e0615ad6decabada/static/img/logo.png -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // the name of the method is the filename. 3 | // can be used in tests like this: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // for how to write custom assertions see 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | exports.assertion = function (selector, count) { 10 | this.message = 'Testing if element <' + selector + '> has count: ' + count 11 | this.expected = count 12 | this.pass = function (val) { 13 | return val === this.expected 14 | } 15 | this.value = function (res) { 16 | return res.value 17 | } 18 | this.command = function (cb) { 19 | var self = this 20 | return this.api.execute(function (selector) { 21 | return document.querySelectorAll(selector).length 22 | }, [selector], function (res) { 23 | cb.call(self, res) 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config') 3 | 4 | // http://nightwatchjs.org/guide#settings-file 5 | module.exports = { 6 | "src_folders": ["test/e2e/specs"], 7 | "output_folder": "test/e2e/reports", 8 | "custom_assertions_path": ["test/e2e/custom-assertions"], 9 | 10 | "selenium": { 11 | "start_process": true, 12 | "server_path": "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar", 13 | "host": "127.0.0.1", 14 | "port": 4444, 15 | "cli_args": { 16 | "webdriver.chrome.driver": require('chromedriver').path 17 | } 18 | }, 19 | 20 | "test_settings": { 21 | "default": { 22 | "selenium_port": 4444, 23 | "selenium_host": "localhost", 24 | "silent": true, 25 | "globals": { 26 | "devServerURL": "http://localhost:" + (process.env.PORT || config.dev.port) 27 | } 28 | }, 29 | 30 | "chrome": { 31 | "desiredCapabilities": { 32 | "browserName": "chrome", 33 | "javascriptEnabled": true, 34 | "acceptSslCerts": true 35 | } 36 | }, 37 | 38 | "firefox": { 39 | "desiredCapabilities": { 40 | "browserName": "firefox", 41 | "javascriptEnabled": true, 42 | "acceptSslCerts": true 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing' 3 | var server = require('../../build/dev-server.js') 4 | 5 | // 2. run the nightwatch test suite against it 6 | // to run in additional browsers: 7 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 8 | // 2. add it to the --env flag below 9 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 10 | // For more information on Nightwatch's config file, see 11 | // http://nightwatchjs.org/guide#settings-file 12 | var opts = process.argv.slice(2) 13 | if (opts.indexOf('--config') === -1) { 14 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 15 | } 16 | if (opts.indexOf('--env') === -1) { 17 | opts = opts.concat(['--env', 'chrome']) 18 | } 19 | 20 | var spawn = require('cross-spawn') 21 | var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 22 | 23 | runner.on('exit', function (code) { 24 | server.close() 25 | process.exit(code) 26 | }) 27 | 28 | runner.on('error', function (err) { 29 | server.close() 30 | throw err 31 | }) 32 | -------------------------------------------------------------------------------- /test/e2e/specs/test.js: -------------------------------------------------------------------------------- 1 | // For authoring Nightwatch tests, see 2 | // http://nightwatchjs.org/guide#usage 3 | 4 | module.exports = { 5 | 'default e2e tests': function (browser) { 6 | // automatically uses dev Server port from /config.index.js 7 | // default: http://localhost:8080 8 | // see nightwatch.conf.js 9 | const devServer = browser.globals.devServerURL 10 | 11 | browser 12 | .url(devServer) 13 | .waitForElementVisible('#app', 5000) 14 | .assert.elementPresent('.logo') 15 | .assert.containsText('h1', 'Hello Vue!') 16 | .assert.elementCount('p', 3) 17 | .end() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | // Polyfill fn.bind() for PhantomJS 2 | /* eslint-disable no-extend-native */ 3 | Function.prototype.bind = require('function-bind') 4 | 5 | // require all test files (files that ends with .spec.js) 6 | const testsContext = require.context('./specs', true, /\.spec$/) 7 | testsContext.keys().forEach(testsContext) 8 | 9 | // require all src files except main.js for coverage. 10 | // you can also change this to match only the subset of files that 11 | // you want coverage for. 12 | const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) 13 | srcContext.keys().forEach(srcContext) 14 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var path = require('path') 7 | var merge = require('webpack-merge') 8 | var baseConfig = require('../../build/webpack.base.conf') 9 | var utils = require('../../build/utils') 10 | var webpack = require('webpack') 11 | var projectRoot = path.resolve(__dirname, '../../') 12 | 13 | var webpackConfig = merge(baseConfig, { 14 | // use inline sourcemap for karma-sourcemap-loader 15 | module: { 16 | loaders: utils.styleLoaders() 17 | }, 18 | devtool: '#inline-source-map', 19 | vue: { 20 | loaders: { 21 | js: 'isparta' 22 | } 23 | }, 24 | plugins: [ 25 | new webpack.DefinePlugin({ 26 | 'process.env': require('../../config/test.env') 27 | }) 28 | ] 29 | }) 30 | 31 | // no need for app entry during tests 32 | delete webpackConfig.entry 33 | 34 | // make sure isparta loader is applied before eslint 35 | webpackConfig.module.preLoaders = webpackConfig.module.preLoaders || [] 36 | webpackConfig.module.preLoaders.unshift({ 37 | test: /\.js$/, 38 | loader: 'isparta', 39 | include: path.resolve(projectRoot, 'src') 40 | }) 41 | 42 | // only apply babel for test files when using isparta 43 | webpackConfig.module.loaders.some(function (loader, i) { 44 | if (loader.loader === 'babel') { 45 | loader.include = path.resolve(projectRoot, 'test/unit') 46 | return true 47 | } 48 | }) 49 | 50 | module.exports = function (config) { 51 | config.set({ 52 | // to run in additional browsers: 53 | // 1. install corresponding karma launcher 54 | // http://karma-runner.github.io/0.13/config/browsers.html 55 | // 2. add it to the `browsers` array below. 56 | browsers: ['PhantomJS'], 57 | frameworks: ['mocha', 'sinon-chai'], 58 | reporters: ['spec', 'coverage'], 59 | files: ['./index.js'], 60 | preprocessors: { 61 | './index.js': ['webpack', 'sourcemap'] 62 | }, 63 | webpack: webpackConfig, 64 | webpackMiddleware: { 65 | noInfo: true 66 | }, 67 | coverageReporter: { 68 | dir: './coverage', 69 | reporters: [ 70 | { type: 'lcov', subdir: '.' }, 71 | { type: 'text-summary' } 72 | ] 73 | } 74 | }) 75 | } 76 | -------------------------------------------------------------------------------- /test/unit/specs/Hello.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Hello from 'src/components/Hello' 3 | 4 | describe('Hello.vue', () => { 5 | it('should render correct contents', () => { 6 | const vm = new Vue({ 7 | el: document.createElement('div'), 8 | render: (h) => h(Hello) 9 | }) 10 | expect(vm.$el.querySelector('.hello h1').textContent).to.equal('Hello Vue!') 11 | }) 12 | }) 13 | --------------------------------------------------------------------------------