├── .eslintrc
├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc
├── LICENSE
├── README.md
├── app
├── _archive.zip
├── _archive
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .lintstagedrc.js
│ ├── .postcssrc.js
│ ├── .prettierrc
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── dep.js
│ │ ├── dev-client.js
│ │ ├── dev-server.js
│ │ ├── genPage.js
│ │ ├── mock.js
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ ├── webpack.dll.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── package.json
│ ├── project.config.json
│ ├── src
│ │ ├── App.vue
│ │ ├── api
│ │ │ └── home.js
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ └── loading.gif
│ │ │ └── styles
│ │ │ │ └── global.less
│ │ ├── common
│ │ │ └── _app.js
│ │ ├── components
│ │ │ └── board.vue
│ │ ├── config
│ │ │ └── index.js
│ │ ├── main.js
│ │ ├── mocks
│ │ │ └── examples.json
│ │ ├── pages
│ │ │ ├── index
│ │ │ │ ├── index.less
│ │ │ │ ├── index.vue
│ │ │ │ └── main.js
│ │ │ ├── sample
│ │ │ │ ├── index.vue
│ │ │ │ └── main.js
│ │ │ └── webview
│ │ │ │ ├── index.less
│ │ │ │ ├── index.vue
│ │ │ │ └── main.js
│ │ ├── store
│ │ │ └── main.js
│ │ └── utils
│ │ │ └── index.js
│ └── static
│ │ └── images
│ │ ├── home-active.png
│ │ ├── home.png
│ │ ├── loading.gif
│ │ ├── success.png
│ │ ├── uc-active.png
│ │ ├── uc.png
│ │ └── warn.png
├── _archive_ts.zip
├── _archive_ts
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .lintstagedrc.js
│ ├── .postcssrc.js
│ ├── .prettierrc
│ ├── .tslintrc.json
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── dep.js
│ │ ├── dev-client.js
│ │ ├── dev-server.js
│ │ ├── genPage.js
│ │ ├── mock.js
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ ├── webpack.dll.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── package.json
│ ├── project.config.json
│ ├── src
│ │ ├── App.vue
│ │ ├── api
│ │ │ └── home.ts
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ └── loading.gif
│ │ │ └── styles
│ │ │ │ └── global.less
│ │ ├── common
│ │ │ └── _app.ts
│ │ ├── components
│ │ │ └── board.vue
│ │ ├── config
│ │ │ └── index.ts
│ │ ├── main.ts
│ │ ├── mocks
│ │ │ └── examples.json
│ │ ├── pages
│ │ │ ├── index
│ │ │ │ ├── index.less
│ │ │ │ ├── index.vue
│ │ │ │ └── main.ts
│ │ │ ├── sample
│ │ │ │ ├── README.md
│ │ │ │ ├── index.vue
│ │ │ │ └── main.ts
│ │ │ ├── sample2
│ │ │ │ ├── README.md
│ │ │ │ ├── index.ts
│ │ │ │ ├── index.vue
│ │ │ │ └── main.ts
│ │ │ └── webview
│ │ │ │ ├── index.less
│ │ │ │ ├── index.vue
│ │ │ │ └── main.ts
│ │ ├── store
│ │ │ └── main.ts
│ │ └── utils
│ │ │ └── index.ts
│ ├── static
│ │ └── images
│ │ │ ├── home-active.png
│ │ │ ├── home.png
│ │ │ ├── loading.gif
│ │ │ ├── success.png
│ │ │ ├── uc-active.png
│ │ │ ├── uc.png
│ │ │ └── warn.png
│ ├── tsconfig.json
│ └── types
│ │ ├── promise.d.ts
│ │ ├── shim.d.ts
│ │ └── vue.d.ts
└── index.js
├── build
└── build.js
├── package.json
├── screenshot
├── screenshot1.png
├── screenshot2.png
├── screenshot3.png
├── screenshot4.png
└── screenshot5.png
├── ts-example
├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .lintstagedrc.js
├── .postcssrc.js
├── .prettierrc
├── .tslintrc.json
├── README.md
├── build
│ ├── build.js
│ ├── check-versions.js
│ ├── dev-client.js
│ ├── dev-server.js
│ ├── mock.js
│ ├── utils.js
│ ├── vue-loader.conf.js
│ ├── webpack.base.conf.js
│ ├── webpack.dev.conf.js
│ ├── webpack.dll.conf.js
│ └── webpack.prod.conf.js
├── config
│ ├── dev.env.js
│ ├── index.js
│ └── prod.env.js
├── package.json
├── project.config.json
├── src
│ ├── App.vue
│ ├── api
│ │ └── home.ts
│ ├── assets
│ │ ├── images
│ │ │ └── loading.gif
│ │ └── styles
│ │ │ └── global.less
│ ├── common
│ │ └── app.ts
│ ├── components
│ │ └── board.vue
│ ├── config
│ │ └── index.ts
│ ├── main.ts
│ ├── mocks
│ │ └── examples.json
│ ├── pages
│ │ ├── index
│ │ │ ├── index.less
│ │ │ ├── index.vue
│ │ │ └── main.ts
│ │ ├── sample
│ │ │ ├── README.md
│ │ │ ├── index.vue
│ │ │ └── main.ts
│ │ ├── sample2
│ │ │ ├── README.md
│ │ │ ├── index.ts
│ │ │ ├── index.vue
│ │ │ └── main.ts
│ │ └── webview
│ │ │ ├── index.less
│ │ │ ├── index.vue
│ │ │ └── main.ts
│ ├── store
│ │ └── main.ts
│ └── utils
│ │ └── index.ts
├── static
│ └── images
│ │ ├── home-active.png
│ │ ├── home.png
│ │ ├── loading.gif
│ │ ├── success.png
│ │ ├── uc-active.png
│ │ ├── uc.png
│ │ └── warn.png
├── tsconfig.json
├── types
│ ├── promise.d.ts
│ ├── shim.d.ts
│ └── vue.d.ts
└── yarn.lock
└── yarn.lock
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["airbnb-base"],
3 | "env": {
4 | "browser": true,
5 | "node": true
6 | },
7 | "parserOptions": {
8 | "parser": "babel-eslint",
9 | "ecmaFeatures": {
10 | "experimentalObjectRestSpread": true,
11 | "jsx": true
12 | },
13 | "sourceType": "module",
14 | "ecmaVersion": 8
15 | },
16 | "rules": {
17 | "indent": [
18 | 1,
19 | 4,
20 | {
21 | "SwitchCase": 2
22 | }
23 | ],
24 | "semi": [2, "always"],
25 | "quotes": [2, "single"],
26 | "comma-dangle": [1, "never"],
27 | "new-cap": [0, { "newIsCap": true }],
28 | "global-require": 0,
29 | "no-console": 0,
30 | "guard-for-in": 1,
31 | "prefer-const": 1,
32 | "object-curly-spacing": 0,
33 | "radix": [0, "as-needed"],
34 | "no-param-reassign": 0,
35 | "no-restricted-syntax": [
36 | 1,
37 | "WithStatement",
38 | "BinaryExpression[operator='in']"
39 | ],
40 | "no-prototype-builtins": 0,
41 | "import/no-dynamic-require": 0,
42 | "object-shorthand": 0,
43 | "arrow-parens": 0,
44 | "func-names": 0,
45 | "no-unused-expressions": 0,
46 | "no-undef": 1,
47 | "no-debugger": 2,
48 | "no-useless-escape": 1,
49 | "generator-star-spacing": 0,
50 | "no-var": 1,
51 | "no-inner-declarations": 0,
52 | "operator-assignment": 0,
53 | "function-paren-newline": 0,
54 | "class-methods-use-this": 0,
55 | "prefer-template": 0,
56 | "space-before-function-paren": 0,
57 | "consistent-return": 0,
58 | "prefer-arrow-callback": 0,
59 | "wrap-iife": 0
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | .vscode/
61 | dist/
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | screenshot/
2 | build/
3 | .eslintrc
4 | .prettierrc
5 | yarn.lock
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | genPage.js
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Touchumind
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## generator-mpvue-project
2 |
3 | A yeoman generator of helping to init your mpvue project
4 |
5 | 基于 mpvue 开发小程序项目的脚手架
6 |
7 | 可直接进[ts-example](ts-example)目录查看生成的项目示例
8 |
9 | * [x] 支持 JS/TS 工程选项,TS 时提供 Typing 智能感知,更好的类型提示
10 | * [x] 支持 API mock 功能,开发时可选使用本地 JSON mock 数据或单独的 API 服务器数据
11 | * [x] 提供通用能力抽象,如 request 库,promisify 话的 wx API,token 以及业务数据持久化的 Store,emitter 跨页面通信等用户只专心写 pages 即可
12 | * [x] 集成众多的工程开发最佳实践: eslint/tslint 代码检查 prettier 代码格式化 lintstaged 和 pre-commit 做 git 钩子完成上述任务
13 |
14 | ** 原生组件依赖解析支持 **
15 |
16 | 在 main.js 中通过`usingComponent`指定原生方式编写的小程序组件 NPM 包名,构建时会自动解析组件包,以及组件包的依赖
17 |
18 | ## Screenshots
19 |
20 | 
21 |
22 | 
23 |
24 | 
25 |
26 | 
27 |
28 | 
29 |
30 | ## Install
31 |
32 | ```
33 | npm install yo -g
34 | npm install generator-mpvue-project -g
35 | ```
36 |
37 | ## Usage
38 |
39 | ```
40 | yo mpvue-project
41 | ```
42 |
--------------------------------------------------------------------------------
/app/_archive.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive.zip
--------------------------------------------------------------------------------
/app/_archive/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/_archive/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/app/_archive/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/app/_archive/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
5 | extends: ['standard', 'plugin:vue/essential'],
6 | // add your custom rules here
7 | rules: {
8 | // allow debugger during development
9 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
10 |
11 | 'wrap-iife': 0,
12 |
13 | 'space-before-function-paren': 0,
14 |
15 | semi: [2, 'always'],
16 |
17 | 'no-new': 0,
18 |
19 | 'vue/mustache-interpolation-spacing': 0,
20 | indent: [
21 | 0,
22 | 4,
23 | {
24 | SwitchCase: 1,
25 | VariableDeclarator: 1,
26 | outerIIFEBody: 1,
27 | FunctionDeclaration: {
28 | parameters: 1,
29 | body: 1
30 | },
31 | FunctionExpression: {
32 | parameters: 1,
33 | body: 1
34 | }
35 | }
36 | ]
37 | },
38 | globals: {
39 | App: true,
40 | Page: true,
41 | wx: true,
42 | getApp: true,
43 | getPage: true,
44 | getCurrentPages: true
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/app/_archive/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | .vscode/
61 | .dll/
62 | dist/
--------------------------------------------------------------------------------
/app/_archive/.lintstagedrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | 'src/**/*.{ts,tsx}': ['lint-staged:format', 'lint-staged:ts', 'git add'],
3 | 'src/**/*.{js,vue}': ['lint-staged:format', 'lint-staged:js', 'git add']
4 | };
5 |
--------------------------------------------------------------------------------
/app/_archive/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {},
7 | "postcss-mpvue-wxss": {}
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/app/_archive/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/app/_archive/README.md:
--------------------------------------------------------------------------------
1 | ## 使用
2 |
3 | 开发
4 |
5 | ```js
6 | npm run dev
7 | ```
8 |
9 | 开发并本地 mock API
10 |
11 | ```js
12 | npm run dev:mock
13 | ```
14 |
15 | 生产打包
16 |
17 | ```js
18 | npm run build
19 | ```
20 |
21 | 快速添加新页面
22 |
23 | ```js
24 | npm run newpage
25 | ```
26 |
27 | ## common-mpvue
28 |
29 | [common-mpvue](https://github.com/thundernet8/common-mpvue)
30 |
--------------------------------------------------------------------------------
/app/_archive/build/build.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')();
2 |
3 | process.env.NODE_ENV = 'production';
4 |
5 | var ora = require('ora');
6 | var rm = require('rimraf');
7 | var path = require('path');
8 | var chalk = require('chalk');
9 | var webpack = require('webpack');
10 | var config = require('../config');
11 | var webpackConfig = require('./webpack.prod.conf');
12 | var depManager = require('./dep');
13 |
14 | var spinner = ora('building for production...');
15 | spinner.start();
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err;
19 | webpack(webpackConfig, function(err, stats) {
20 | spinner.stop();
21 | if (err) throw err;
22 | process.stdout.write(
23 | stats.toString({
24 | colors: true,
25 | modules: false,
26 | children: false,
27 | chunks: false,
28 | chunkModules: false
29 | }) + '\n\n'
30 | );
31 |
32 | if (stats.hasErrors()) {
33 | console.log(chalk.red(' Build failed with errors.\n'));
34 | process.exit(1);
35 | }
36 |
37 | depManager.scanDeps();
38 |
39 | console.log(chalk.cyan(' Build complete.\n'));
40 | console.log(
41 | chalk.yellow(
42 | ' Tip: built files are meant to be served over an HTTP server.\n' +
43 | " Opening index.html over file:// won't work.\n"
44 | )
45 | );
46 | });
47 | });
48 |
--------------------------------------------------------------------------------
/app/_archive/build/check-versions.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk');
2 | var semver = require('semver');
3 | var packageConfig = require('../package.json');
4 | var shell = require('shelljs');
5 | function exec(cmd) {
6 | return require('child_process')
7 | .execSync(cmd)
8 | .toString()
9 | .trim();
10 | }
11 |
12 | var versionRequirements = [
13 | {
14 | name: 'node',
15 | currentVersion: semver.clean(process.version),
16 | versionRequirement: packageConfig.engines.node
17 | }
18 | ];
19 |
20 | if (shell.which('npm')) {
21 | versionRequirements.push({
22 | name: 'npm',
23 | currentVersion: exec('npm --version'),
24 | versionRequirement: packageConfig.engines.npm
25 | });
26 | }
27 |
28 | module.exports = function() {
29 | var warnings = [];
30 | for (var i = 0; i < versionRequirements.length; i++) {
31 | var mod = versionRequirements[i];
32 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
33 | warnings.push(
34 | mod.name +
35 | ': ' +
36 | chalk.red(mod.currentVersion) +
37 | ' should be ' +
38 | chalk.green(mod.versionRequirement)
39 | );
40 | }
41 | }
42 |
43 | if (warnings.length) {
44 | console.log('');
45 | console.log(
46 | chalk.yellow(
47 | 'To use this template, you must update following to modules:'
48 | )
49 | );
50 | console.log();
51 | for (var i = 0; i < warnings.length; i++) {
52 | var warning = warnings[i];
53 | console.log(' ' + warning);
54 | }
55 | console.log();
56 | process.exit(1);
57 | }
58 | };
59 |
--------------------------------------------------------------------------------
/app/_archive/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 |
--------------------------------------------------------------------------------
/app/_archive/build/genPage.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const path = require('path');
3 | const inquirer = require('inquirer');
4 | const prettier = require('prettier');
5 | const prettierBaseConfig = {
6 | tabWidth: 4,
7 | useTabs: false,
8 | singleQuote: false,
9 | bracketSpacing: true
10 | };
11 | const prettierJsonConfig = Object.assign({}, prettierBaseConfig, {
12 | parser: 'json'
13 | });
14 | const prettierJsConfig = Object.assign({}, prettierBaseConfig, {
15 | parser: 'typescript'
16 | });
17 | const prettierCssConfig = Object.assign({}, prettierBaseConfig, {
18 | parser: 'css'
19 | });
20 |
21 | const PAGES_ROOT = path.resolve(process.cwd(), 'src/pages');
22 |
23 | const isTsProject = fs.existsSync(path.resolve(process.cwd(), 'src/main.ts'));
24 |
25 | function promptForPage() {
26 | const pages = fs.readdirSync(PAGES_ROOT).map(page => page.toLowerCase());
27 | const question = {
28 | type: 'input',
29 | name: 'page',
30 | message: '输入要新建的page',
31 | default: '',
32 | validate(input) {
33 | return new Promise((resolve, reject) => {
34 | input = String.prototype.toLowerCase.call(input);
35 | if (!input) {
36 | reject(new Error('请输入Page的名称'));
37 | } else if (pages.includes(input)) {
38 | reject(new Error('该Page已存在'));
39 | } else if (!/^[a-z]+$/i.test(input)) {
40 | reject(new Error('Page的名称必须为a-z组成'));
41 | }
42 | resolve(true);
43 | });
44 | }
45 | };
46 |
47 | return inquirer
48 | .prompt(question)
49 | .then(answer => String.prototype.toLowerCase.call(answer.page));
50 | }
51 |
52 | function addPage(page) {
53 | const pageFolder = path.resolve(PAGES_ROOT, page);
54 | fs.mkdirSync(pageFolder);
55 | // style
56 | const less = `.wrapper {position: relative;}`;
57 | fs.writeFileSync(
58 | path.resolve(pageFolder, 'index.less'),
59 | prettier.format(less, prettierCssConfig)
60 | );
61 | // main.js/ts
62 | if (!isTsProject) {
63 | const mainJs = `import Page from './index';
64 | import { WrapPage } from 'common-mpvue';
65 |
66 | new WrapPage(Page);
67 |
68 | export default {
69 | config: {
70 | backgroundTextStyle: 'black',
71 | navigationBarBackgroundColor: '#ffffff',
72 | navigationBarTitleText: '页面标题',
73 | navigationBarTextStyle: 'black'
74 | }
75 | };
76 | `;
77 | fs.writeFileSync(
78 | path.resolve(pageFolder, 'main.js'),
79 | prettier.format(mainJs, prettierJsConfig)
80 | );
81 | } else {
82 | const mainJs = `import Page from "./index.vue";
83 | import { WrapPage } from "common-mpvue";
84 |
85 | /* tslint:disable */
86 | new WrapPage(Page);
87 | /* tslint:enable */
88 |
89 | export default {
90 | config: {
91 | backgroundTextStyle: "black",
92 | navigationBarBackgroundColor: "#ffffff",
93 | navigationBarTitleText: "页面标题",
94 | navigationBarTextStyle: "black"
95 | }
96 | };
97 | `;
98 | fs.writeFileSync(
99 | path.resolve(pageFolder, 'main.ts'),
100 | prettier.format(mainJs, prettierJsConfig)
101 | );
102 | }
103 | // index.vue
104 | let vue;
105 | if (!isTsProject) {
106 | vue = `
107 |
108 | 页面${page}
109 |
110 |
111 |
112 |
126 |
127 |
130 | `;
131 | } else {
132 | vue = `
133 |
134 | 页面${page}
135 |
136 |
137 |
138 |
139 |
140 |
143 | `;
144 | }
145 | fs.writeFileSync(path.resolve(pageFolder, 'index.vue'), vue);
146 |
147 | // index.ts
148 | if (isTsProject) {
149 | const className = page.split('').map((char, index) => {
150 | if (index === 0) {
151 | return char.toUpperCase();
152 | }
153 | return char.toLowerCase();
154 | }).join('');
155 | const tsScript = `import board from '@/components/board.vue';
156 | import { getApp, wx, wxp } from 'common-mpvue';
157 | import { Component } from 'vue-property-decorator';
158 | import Vue from 'vue';
159 |
160 | @Component({
161 | components: {
162 | board
163 | }
164 | })
165 | export default class ${className} extends Vue {
166 | // props
167 | text: string = '';
168 |
169 | // computed:
170 | get upperText() {
171 | return this.text.toUpperCase()
172 | }
173 |
174 | // method
175 | updateText(text: string) {
176 | this.text = text;
177 | }
178 |
179 | onLoad() {}
180 |
181 | onShow() {}
182 |
183 | onReady() {}
184 |
185 | onUnload() {}
186 | }
187 | `;
188 | fs.writeFileSync(
189 | path.resolve(pageFolder, 'index.ts'),
190 | prettier.format(tsScript, prettierJsConfig)
191 | );
192 | }
193 | }
194 |
195 | promptForPage().then(page => {
196 | addPage(page);
197 | });
198 |
--------------------------------------------------------------------------------
/app/_archive/build/mock.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const fs = require('fs');
3 |
4 | module.exports = function mock(req, res) {
5 | const reqPath = req.path.slice(1);
6 | const jsonPath = path.resolve(__dirname, '../src', `${reqPath}.json`);
7 | console.log(`[** mocks **]: use ${jsonPath}`);
8 | try {
9 | // TODO require有缓存,在运行过程中修改json不会生效,需要重启dev server
10 | // TODO fs.readFileSync
11 | // const json = require(jsonPath);
12 | const json = fs.readFileSync(jsonPath).toString();
13 | res.json(JSON.parse(json));
14 | } catch (e) {
15 | if (e.message && e.message.indexOf('no such file or directory') > -1) {
16 | console.log('Mock json file not found');
17 | // res.json(JSON.stringify({}));
18 | res.status(404).end(`Mock json file not found: ${jsonPath}`);
19 | return;
20 | }
21 | throw e;
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/app/_archive/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 =
7 | process.env.NODE_ENV === 'production'
8 | ? config.build.assetsSubDirectory
9 | : config.dev.assetsSubDirectory;
10 | return path.posix.join(assetsSubDirectory, _path);
11 | };
12 |
13 | exports.cssLoaders = function(options) {
14 | options = options || {};
15 |
16 | var cssLoader = {
17 | loader: 'css-loader',
18 | options: {
19 | minimize: process.env.NODE_ENV === 'production',
20 | sourceMap: options.sourceMap
21 | }
22 | };
23 |
24 | var postcssLoader = {
25 | loader: 'postcss-loader',
26 | options: {
27 | sourceMap: true
28 | }
29 | };
30 |
31 | var px2rpxLoader = {
32 | loader: 'px2rpx-loader',
33 | options: {
34 | baseDpr: 1,
35 | rpxUnit: 0.5
36 | }
37 | };
38 |
39 | // generate loader string to be used with extract text plugin
40 | function generateLoaders(loader, loaderOptions) {
41 | var loaders = [cssLoader, postcssLoader, px2rpxLoader];
42 | if (loader) {
43 | loaders.push({
44 | loader: loader + '-loader',
45 | options: Object.assign({}, loaderOptions, {
46 | sourceMap: options.sourceMap
47 | })
48 | });
49 | }
50 |
51 | // Extract CSS when that option is specified
52 | // (which is the case during production build)
53 | if (options.extract) {
54 | return ExtractTextPlugin.extract({
55 | use: loaders,
56 | fallback: 'vue-style-loader'
57 | });
58 | } else {
59 | return ['vue-style-loader'].concat(loaders);
60 | }
61 | }
62 |
63 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
64 | return {
65 | css: generateLoaders(),
66 | postcss: generateLoaders(),
67 | less: generateLoaders('less'),
68 | sass: generateLoaders('sass', { indentedSyntax: true }),
69 | scss: generateLoaders('sass'),
70 | stylus: generateLoaders('stylus'),
71 | styl: generateLoaders('stylus')
72 | };
73 | };
74 |
75 | // Generate loaders for standalone style files (outside of .vue)
76 | exports.styleLoaders = function(options) {
77 | var output = [];
78 | var loaders = exports.cssLoaders(options);
79 | for (var extension in loaders) {
80 | var loader = loaders[extension];
81 | output.push({
82 | test: new RegExp('\\.' + extension + '$'),
83 | use: loader
84 | });
85 | }
86 | return output;
87 | };
88 |
--------------------------------------------------------------------------------
/app/_archive/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var config = require('../config');
3 | // var isProduction = process.env.NODE_ENV === 'production'
4 | // for mp
5 | var isProduction = true;
6 |
7 | module.exports = {
8 | loaders: utils.cssLoaders({
9 | sourceMap: isProduction
10 | ? config.build.productionSourceMap
11 | : config.dev.cssSourceMap,
12 | extract: isProduction
13 | }),
14 | transformToRequire: {
15 | video: 'src',
16 | source: 'src',
17 | img: 'src',
18 | image: 'xlink:href'
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/app/_archive/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var fs = require('fs');
3 | var utils = require('./utils');
4 | var config = require('../config');
5 | var vueLoaderConfig = require('./vue-loader.conf');
6 | var webpack = require('webpack');
7 | var StringReplacePlugin = require('string-replace-webpack-plugin');
8 | var CopyWebpackPlugin = require('copy-webpack-plugin');
9 | var MpvuePlugin = require('webpack-mpvue-asset-plugin');
10 |
11 | function resolve(dir) {
12 | return path.join(__dirname, '..', dir);
13 | }
14 |
15 | function getEntry(dir, entryFile) {
16 | const files = fs.readdirSync(dir);
17 | return files.reduce((res, k) => {
18 | const page = path.resolve(dir, k, entryFile);
19 | if (fs.existsSync(page)) {
20 | res[k] = page;
21 | }
22 | return res;
23 | }, {});
24 | }
25 |
26 | const appEntry = { app: resolve('./src/main.js') };
27 | const pagesEntry = getEntry(resolve('./src/pages'), 'main.js');
28 | const entry = Object.assign({}, appEntry, pagesEntry);
29 |
30 | // const replaceStrLoader = StringReplacePlugin.replace({
31 | // replacements: [
32 | // {
33 | // pattern: /(wx.)(navigateTo|redirectTo)\(/g,
34 | // replacement(match, p1) {
35 | // return match.replace(p1, 'wx._');
36 | // }
37 | // }
38 | // ]
39 | // });
40 |
41 | module.exports = {
42 | entry: entry,
43 | target: require('mpvue-webpack-target'),
44 | output: {
45 | path: config.build.assetsRoot,
46 | filename: '[name].js',
47 | publicPath:
48 | process.env.NODE_ENV === 'production'
49 | ? config.build.assetsPublicPath
50 | : config.dev.assetsPublicPath
51 | },
52 | resolve: {
53 | extensions: ['.js', '.ts', '.vue', '.json'],
54 | alias: {
55 | vue: 'mpvue',
56 | '@': resolve('src')
57 | },
58 | symlinks: false
59 | },
60 | module: {
61 | rules: [
62 | {
63 | test: /\.css$/,
64 | use: utils.cssLoaders().css
65 | },
66 | {
67 | test: /\.less$/,
68 | use: utils.cssLoaders().less
69 | },
70 | // {
71 | // test: /\.(js|vue)$/,
72 | // loader: 'eslint-loader',
73 | // enforce: 'pre',
74 | // include: [resolve('src'), resolve('test')],
75 | // options: {
76 | // formatter: require('eslint-friendly-formatter')
77 | // }
78 | // },
79 | {
80 | test: /\.ts$/,
81 | use: [
82 | {
83 | loader: 'babel-loader'
84 | },
85 | {
86 | loader: 'mpvue-loader',
87 | options: {
88 | checkMPEntry: true
89 | }
90 | },
91 | // {
92 | // loader: replaceStrLoader
93 | // },
94 | {
95 | loader: 'ts-loader',
96 | options: {
97 | appendTsSuffixTo: [/\.vue$/]
98 | }
99 | }
100 | ],
101 | exclude: /node_modules/
102 | },
103 | {
104 | test: /\.vue$/,
105 | use: [
106 | {
107 | loader: 'mpvue-loader',
108 | options: vueLoaderConfig
109 | }
110 | // {
111 | // loader: replaceStrLoader
112 | // }
113 | ]
114 | },
115 | {
116 | test: /\.js$/,
117 | include: [
118 | resolve('src'),
119 | resolve('test'),
120 | resolve('node_modules/common-mpvue')
121 | ],
122 | use: [
123 | 'babel-loader',
124 | {
125 | loader: 'mpvue-loader',
126 | options: {
127 | checkMPEntry: true
128 | }
129 | }
130 | // {
131 | // loader: replaceStrLoader
132 | // }
133 | ]
134 | },
135 | {
136 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
137 | loader: 'url-loader',
138 | options: {
139 | limit: 10000,
140 | name: utils.assetsPath('img/[name].[ext]')
141 | }
142 | },
143 | {
144 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
145 | loader: 'url-loader',
146 | options: {
147 | limit: 10000,
148 | name: utils.assetsPath('media/[name]].[ext]')
149 | }
150 | },
151 | {
152 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
153 | loader: 'url-loader',
154 | options: {
155 | limit: 10000,
156 | name: utils.assetsPath('fonts/[name].[ext]')
157 | }
158 | }
159 | ]
160 | },
161 | plugins: [
162 | new webpack.DllReferencePlugin({
163 | context: __dirname,
164 | manifest: require('../.dll/manifest.json'),
165 | name: `../../dll${
166 | process.env.NODE_ENV === 'production' ? '' : '-dev'
167 | }.js`,
168 | sourceType: 'commonjs2'
169 | }),
170 | new StringReplacePlugin(),
171 | new CopyWebpackPlugin([
172 | {
173 | from: path.resolve(__dirname, '../project.config.json'),
174 | to: path.resolve(__dirname, '../dist')
175 | }
176 | ]),
177 | new MpvuePlugin()
178 | ]
179 | };
180 |
--------------------------------------------------------------------------------
/app/_archive/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var webpack = require('webpack');
3 | var config = require('../config');
4 | var merge = require('webpack-merge');
5 | var baseWebpackConfig = require('./webpack.base.conf');
6 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
8 |
9 | // copy from ./webpack.prod.conf.js
10 | var path = require('path');
11 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
12 | var CopyWebpackPlugin = require('copy-webpack-plugin');
13 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
14 |
15 | // add hot-reload related code to entry chunks
16 | // Object.keys(baseWebpackConfig.entry).forEach(function (name) {
17 | // baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
18 | // })
19 |
20 | module.exports = merge(baseWebpackConfig, {
21 | module: {
22 | rules: utils.styleLoaders({
23 | sourceMap: config.dev.cssSourceMap,
24 | extract: true
25 | })
26 | },
27 | // cheap-module-eval-source-map is faster for development
28 | // devtool: '#cheap-module-eval-source-map',
29 | devtool: '#source-map',
30 | output: {
31 | path: config.build.assetsRoot,
32 | // filename: utils.assetsPath('js/[name].[chunkhash].js'),
33 | // chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
34 | filename: utils.assetsPath('js/[name].js'),
35 | chunkFilename: utils.assetsPath('js/[id].js')
36 | },
37 | plugins: [
38 | new webpack.DefinePlugin({
39 | 'process.env': config.dev.env
40 | }),
41 |
42 | // copy from ./webpack.prod.conf.js
43 | // extract css into its own file
44 | new ExtractTextPlugin({
45 | // filename: utils.assetsPath('css/[name].[contenthash].css')
46 | filename: utils.assetsPath('css/[name].wxss')
47 | }),
48 | // Compress extracted CSS. We are using this plugin so that possible
49 | // duplicated CSS from different components can be deduped.
50 | new OptimizeCSSPlugin({
51 | cssProcessorOptions: {
52 | safe: true
53 | }
54 | }),
55 | new webpack.optimize.CommonsChunkPlugin({
56 | name: 'vendor',
57 | minChunks: function(module, count) {
58 | // any required modules inside node_modules are extracted to vendor
59 | return (
60 | module.resource &&
61 | /\.js$/.test(module.resource) &&
62 | module.resource.indexOf('node_modules') >= 0
63 | );
64 | }
65 | }),
66 | new webpack.optimize.CommonsChunkPlugin({
67 | name: 'manifest',
68 | chunks: ['vendor']
69 | }),
70 | // copy custom static assets
71 | new CopyWebpackPlugin([
72 | {
73 | from: path.resolve(__dirname, '../static'),
74 | to: config.build.assetsSubDirectory,
75 | ignore: ['.*']
76 | }
77 | ]),
78 |
79 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
80 | // new webpack.HotModuleReplacementPlugin(),
81 | new webpack.NoEmitOnErrorsPlugin(),
82 | // https://github.com/ampedandwired/html-webpack-plugin
83 | // new HtmlWebpackPlugin({
84 | // filename: 'index.html',
85 | // template: 'index.html',
86 | // inject: true
87 | // }),
88 | new FriendlyErrorsPlugin()
89 | ]
90 | });
91 |
--------------------------------------------------------------------------------
/app/_archive/build/webpack.dll.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var config = require('../config');
3 | var webpack = require('webpack');
4 |
5 | function resolve(dir) {
6 | return path.join(__dirname, '..', dir);
7 | }
8 |
9 | const plugins = [];
10 | if (config.build.bundleAnalyzerReport) {
11 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
12 | .BundleAnalyzerPlugin;
13 | plugins.push(new BundleAnalyzerPlugin());
14 | }
15 |
16 | module.exports = {
17 | entry: {
18 | dll: [
19 | 'mpvue',
20 | 'vuex',
21 | 'common-mpvue',
22 | 'querystring',
23 | 'url-parse',
24 | 'md5',
25 | 'left-pad',
26 | 'date-fns'
27 | ]
28 | },
29 | output: {
30 | path: path.resolve(__dirname, '../dist'), //config.build.assetsRoot,
31 | filename:
32 | process.env.NODE_ENV === 'production' ? 'dll.js' : 'dll-dev.js',
33 | publicPath:
34 | process.env.NODE_ENV === 'production'
35 | ? config.build.assetsPublicPath
36 | : config.dev.assetsPublicPath,
37 | library: 'dll',
38 | libraryTarget: 'commonjs2'
39 | },
40 | resolve: {
41 | extensions: ['.js', '.json'],
42 | alias: {
43 | vue: 'mpvue',
44 | '@': resolve('src')
45 | },
46 | symlinks: false
47 | },
48 | module: {
49 | rules: [
50 | {
51 | test: /\.js$/,
52 | include: [resolve('src'), resolve('test')],
53 | use: ['babel-loader']
54 | }
55 | ]
56 | },
57 | plugins: [
58 | ...plugins,
59 | new webpack.DllPlugin({
60 | context: __dirname,
61 | path: '.dll/manifest.json',
62 | name: '[name]'
63 | }),
64 | new webpack.HashedModuleIdsPlugin()
65 | // new webpack.optimize.UglifyJsPlugin({
66 | // compress: {
67 | // warnings: false
68 | // },
69 | // sourceMap: false
70 | // })
71 | ]
72 | };
73 |
--------------------------------------------------------------------------------
/app/_archive/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var utils = require('./utils');
3 | var webpack = require('webpack');
4 | var config = require('../config');
5 | var merge = require('webpack-merge');
6 | var baseWebpackConfig = require('./webpack.base.conf');
7 | var CopyWebpackPlugin = require('copy-webpack-plugin');
8 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
9 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
11 | var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
12 |
13 | var env = config.build.env;
14 |
15 | var webpackConfig = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({
18 | sourceMap: config.build.productionSourceMap,
19 | extract: true
20 | })
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 | filename: utils.assetsPath('js/[name].js'),
28 | chunkFilename: utils.assetsPath('js/[id].js')
29 | },
30 | plugins: [
31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
32 | new webpack.DefinePlugin({
33 | 'process.env': env
34 | }),
35 | new UglifyJsPlugin({
36 | sourceMap: true
37 | }),
38 | // extract css into its own file
39 | new ExtractTextPlugin({
40 | // filename: utils.assetsPath('css/[name].[contenthash].css')
41 | filename: utils.assetsPath('css/[name].wxss')
42 | }),
43 | // Compress extracted CSS. We are using this plugin so that possible
44 | // duplicated CSS from different components can be deduped.
45 | new OptimizeCSSPlugin({
46 | cssProcessorOptions: {
47 | safe: true
48 | }
49 | }),
50 | // generate dist index.html with correct asset hash for caching.
51 | // you can customize output by editing /index.html
52 | // see https://github.com/ampedandwired/html-webpack-plugin
53 | // new HtmlWebpackPlugin({
54 | // filename: config.build.index,
55 | // template: 'index.html',
56 | // inject: true,
57 | // minify: {
58 | // removeComments: true,
59 | // collapseWhitespace: true,
60 | // removeAttributeQuotes: true
61 | // // more options:
62 | // // https://github.com/kangax/html-minifier#options-quick-reference
63 | // },
64 | // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
65 | // chunksSortMode: 'dependency'
66 | // }),
67 | // keep module.id stable when vender modules does not change
68 | new webpack.HashedModuleIdsPlugin(),
69 | // split vendor js into its own file
70 | new webpack.optimize.CommonsChunkPlugin({
71 | name: 'vendor',
72 | minChunks: function(module, count) {
73 | // any required modules inside node_modules are extracted to vendor
74 | return (
75 | module.resource &&
76 | /\.js$/.test(module.resource) &&
77 | module.resource.indexOf('node_modules') >= 0
78 | );
79 | }
80 | }),
81 | // extract webpack runtime and module manifest to its own file in order to
82 | // prevent vendor hash from being updated whenever app bundle is updated
83 | new webpack.optimize.CommonsChunkPlugin({
84 | name: 'manifest',
85 | chunks: ['vendor']
86 | }),
87 | // copy custom static assets
88 | new CopyWebpackPlugin([
89 | {
90 | from: path.resolve(__dirname, '../static'),
91 | to: config.build.assetsSubDirectory,
92 | ignore: ['.*']
93 | }
94 | ])
95 | ]
96 | });
97 |
98 | // if (config.build.productionGzip) {
99 | // var CompressionWebpackPlugin = require('compression-webpack-plugin')
100 |
101 | // webpackConfig.plugins.push(
102 | // new CompressionWebpackPlugin({
103 | // asset: '[path].gz[query]',
104 | // algorithm: 'gzip',
105 | // test: new RegExp(
106 | // '\\.(' +
107 | // config.build.productionGzipExtensions.join('|') +
108 | // ')$'
109 | // ),
110 | // threshold: 10240,
111 | // minRatio: 0.8
112 | // })
113 | // )
114 | // }
115 |
116 | if (config.build.bundleAnalyzerReport) {
117 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
118 | .BundleAnalyzerPlugin;
119 | webpackConfig.plugins.push(new BundleAnalyzerPlugin());
120 | }
121 |
122 | module.exports = webpackConfig;
123 |
--------------------------------------------------------------------------------
/app/_archive/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 | PORT: 8080,
7 | MOCK: process.env.MOCK,
8 | PKG_TYPE: process.env.PKG_TYPE
9 | });
10 |
--------------------------------------------------------------------------------
/app/_archive/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path');
3 | var env = require('./dev.env');
4 |
5 | module.exports = {
6 | build: {
7 | env: require('./prod.env'),
8 | index: path.resolve(__dirname, '../dist/index.html'),
9 | assetsRoot: path.resolve(__dirname, '../dist'),
10 | assetsSubDirectory: 'static',
11 | assetsPublicPath: '/',
12 | productionSourceMap: false,
13 | // Gzip off by default as many popular static hosts such as
14 | // Surge or Netlify already gzip all static assets for you.
15 | // Before setting to `true`, make sure to:
16 | // npm install --save-dev compression-webpack-plugin
17 | productionGzip: false,
18 | productionGzipExtensions: ['js', 'css'],
19 | // Run the build command with an extra argument to
20 | // View the bundle analyzer report after build finishes:
21 | // `npm run build --report`
22 | // Set to `true` or `false` to always turn it on or off
23 | bundleAnalyzerReport: process.env.npm_config_report
24 | },
25 | dev: {
26 | env,
27 | port: env.PORT,
28 | // 在小程序开发者工具中不需要自动打开浏览器
29 | autoOpenBrowser: false,
30 | assetsSubDirectory: 'static',
31 | assetsPublicPath: '/',
32 | proxyTable: {},
33 | // CSS Sourcemaps off by default because relative paths are "buggy"
34 | // with this option, according to the CSS-Loader README
35 | // (https://github.com/webpack/css-loader#sourcemaps)
36 | // In our experience, they generally work as expected,
37 | // just be aware of this issue when enabling this option.
38 | cssSourceMap: false
39 | }
40 | };
41 |
--------------------------------------------------------------------------------
/app/_archive/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | };
4 |
--------------------------------------------------------------------------------
/app/_archive/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sample-mpvue-wxapp",
3 | "version": "1.0.0",
4 | "description": "example project of miniprogram developed via mpvue",
5 | "private": true,
6 | "scripts": {
7 | "lint-staged": "lint-staged -c .lintstagedrc.js",
8 | "lint": "npm run lint:js",
9 | "lint:js": "eslint --fix --ext .js,.vue src",
10 | "lint-staged:js": "eslint --fix -c .eslintrc.js",
11 | "lint-staged:format": "prettier --write",
12 | "format":
13 | "prettier --write --tab-width 4 --single-quote true --stdin-filepath src/**/*.{less,vue,js}",
14 | "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
15 | "dll":
16 | "cross-env NODE_ENV=production webpack -p --hide-modules --config build/webpack.dll.conf.js",
17 | "dll:dev":
18 | "cross-env NODE_ENV=development webpack --hide-modules --config build/webpack.dll.conf.js",
19 | "dll:report":
20 | "cross-env npm_config_report=true NODE_ENV=production webpack --hide-modules --config build/webpack.dll.conf.js",
21 | "dev": "node build/dev-server.js",
22 | "dev:mock": "cross-env MOCK=true node build/dev-server.js",
23 | "start": "npm run dll:dev && node build/dev-server.js",
24 | "build": " rimraf dist && npm run dll && node build/build.js",
25 | "build:report":
26 | "rimraf dist && npm run dll && cross-env npm_config_report=true node build/build.js",
27 | "newpage": "node build/genPage.js"
28 | },
29 | "dependencies": {
30 | "common-mpvue": "latest",
31 | "date-fns": "^1.29.0",
32 | "left-pad": "^1.2.0",
33 | "md5": "^2.2.1",
34 | "mpvue": "^1.0.12",
35 | "querystring": "^0.2.0",
36 | "url-parse": "^1.2.0",
37 | "vuex": "^3.0.1"
38 | },
39 | "devDependencies": {
40 | "autoprefixer": "^7.1.2",
41 | "babel-core": "^6.22.1",
42 | "babel-eslint": "^7.1.1",
43 | "babel-loader": "^7.1.1",
44 | "babel-plugin-module-resolver": "^3.1.1",
45 | "babel-plugin-transform-runtime": "^6.22.0",
46 | "babel-preset-env": "^1.3.2",
47 | "babel-preset-stage-2": "^6.22.0",
48 | "babel-register": "^6.22.0",
49 | "chalk": "^2.0.1",
50 | "chokidar": "^2.0.2",
51 | "connect-history-api-fallback": "^1.3.0",
52 | "copy-webpack-plugin": "^4.5.1",
53 | "cross-env": "^5.1.4",
54 | "css-loader": "^0.28.0",
55 | "cssnano": "^3.10.0",
56 | "eslint": "^4.19.1",
57 | "eslint-config-standard": "^11.0.0",
58 | "eslint-friendly-formatter": "^3.0.0",
59 | "eslint-loader": "^1.7.1",
60 | "eslint-plugin-html": "^3.0.0",
61 | "eslint-plugin-import": "^2.10.0",
62 | "eslint-plugin-node": "^6.0.1",
63 | "eslint-plugin-promise": "^3.4.0",
64 | "eslint-plugin-standard": "^2.0.1",
65 | "eslint-plugin-vue": "^4.4.0",
66 | "eventsource-polyfill": "^0.9.6",
67 | "express": "^4.14.1",
68 | "extract-text-webpack-plugin": "^2.0.0",
69 | "file-loader": "^0.11.1",
70 | "friendly-errors-webpack-plugin": "^1.1.3",
71 | "html-webpack-plugin": "^2.28.0",
72 | "http-proxy-middleware": "^0.17.3",
73 | "koa": "^2.5.0",
74 | "less": "^3.0.1",
75 | "less-loader": "^4.1.0",
76 | "lint-staged": "^6.1.1",
77 | "mkdirp": "^0.5.1",
78 | "mpvue-loader": "^1.0.14",
79 | "mpvue-template-compiler": "^1.0.12",
80 | "mpvue-webpack-target": "^1.0.0",
81 | "opn": "^5.1.0",
82 | "optimize-css-assets-webpack-plugin": "^2.0.0",
83 | "ora": "^1.2.0",
84 | "postcss-loader": "^2.0.6",
85 | "postcss-mpvue-wxss": "^1.0.0",
86 | "pre-commit": "^1.2.2",
87 | "prettier": "^1.11.1",
88 | "px2rpx-loader": "^0.1.8",
89 | "replace-ext": "^1.0.0",
90 | "resolve": "^1.7.1",
91 | "rimraf": "^2.6.2",
92 | "semver": "^5.3.0",
93 | "shelljs": "^0.7.6",
94 | "string-replace-webpack-plugin": "^0.1.3",
95 | "stylelint": "^9.1.3",
96 | "uglifyjs-webpack-plugin": "^1.2.4",
97 | "url-loader": "^0.5.8",
98 | "vue-style-loader": "^3.0.1",
99 | "webpack": "^2.6.1",
100 | "webpack-bundle-analyzer": "^2.2.1",
101 | "webpack-dev-middleware": "^1.10.0",
102 | "webpack-dev-middleware-hard-disk": "^1.10.0",
103 | "webpack-hot-middleware": "^2.18.0",
104 | "webpack-merge": "^4.1.0",
105 | "webpack-mpvue-asset-plugin": "^0.0.2"
106 | },
107 | "engines": {
108 | "node": ">= 4.0.0",
109 | "npm": ">= 3.0.0"
110 | },
111 | "browserslist": ["> 1%", "last 2 versions", "not ie <= 8"],
112 | "pre-commit": ["precommit-msg", "lint-staged"]
113 | }
114 |
--------------------------------------------------------------------------------
/app/_archive/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": false,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "compileType": "miniprogram",
11 | "libVersion": "1.9.93",
12 | "appid": "",
13 | "projectname": "sample-mpvue-wxapp",
14 | "isGameTourist": false,
15 | "condition": {
16 | "search": {
17 | "current": -1,
18 | "list": []
19 | },
20 | "conversation": {
21 | "current": -1,
22 | "list": []
23 | },
24 | "game": {
25 | "currentL": -1,
26 | "list": []
27 | },
28 | "miniprogram": {
29 | "current": -1,
30 | "list": []
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/_archive/src/App.vue:
--------------------------------------------------------------------------------
1 |
29 |
30 |
33 |
--------------------------------------------------------------------------------
/app/_archive/src/api/home.js:
--------------------------------------------------------------------------------
1 | const httpRequest = wx.httpRequest
2 | .auth()
3 | .tokenKey('token')
4 | .qsToken();
5 |
6 | // 示例请求
7 | export function exampleRequest() {
8 | return httpRequest.GET('/examples');
9 | }
10 |
--------------------------------------------------------------------------------
/app/_archive/src/assets/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/src/assets/images/loading.gif
--------------------------------------------------------------------------------
/app/_archive/src/assets/styles/global.less:
--------------------------------------------------------------------------------
1 | .container {
2 | font-family: 'Microsoft YaHei', Helvetica, STHeiTi, sans-seri;
3 | position: relative;
4 | background-color: #e7e7e7;
5 | display: flex;
6 | flex-direction: column;
7 | min-height: 100vh;
8 | & > .section {
9 | flex-shrink: 0;
10 | flex-grow: 0;
11 | }
12 | .placeholder-container {
13 | flex: 1;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/_archive/src/common/_app.js:
--------------------------------------------------------------------------------
1 | // 扩展app实例的方法和属性
2 | export default {
3 | getName() {
4 | return this.name;
5 | }
6 | };
7 |
--------------------------------------------------------------------------------
/app/_archive/src/components/board.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{title}}
4 |
{{content}}
5 |
6 |
7 |
8 |
25 |
26 |
42 |
--------------------------------------------------------------------------------
/app/_archive/src/config/index.js:
--------------------------------------------------------------------------------
1 | const DOMAIN_MAP = {
2 | development: process.env.MOCK
3 | ? `http://localhost:${process.env.PORT}/mocks`
4 | : 'http://beta.example.com',
5 | beta: 'http://beta.example.com',
6 | production: 'https://api.example.com'
7 | };
8 |
9 | export default {
10 | VERSION: '1.0.0',
11 | APP_NAME: 'sample-mpvue-wxapp',
12 | MOCK: process.env.MOCK === true,
13 | DEBUG: process.env.NODE_ENV !== 'production',
14 | DOMAIN:
15 | DOMAIN_MAP[process.env.NODE_ENV || 'production'] ||
16 | 'https://api.example.com'
17 | };
18 |
--------------------------------------------------------------------------------
/app/_archive/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import App from './App';
3 | import { wrap } from 'common-mpvue';
4 | import config from './config';
5 | import pkg from '../package.json';
6 | import appProps from './common/_app';
7 |
8 | // 设置wx debug模式
9 | if (process.env.NODE_ENV !== 'production') {
10 | wx.setEnableDebug({ enableDebug: true });
11 | }
12 |
13 | Vue.config.productionTip = false;
14 | wrap(
15 | App,
16 | {
17 | name: config.APP_NAME,
18 | version: config.VERSION,
19 | pkgName: pkg.name,
20 | domain: config.DOMAIN,
21 | env: config.DEBUG ? 'development' : 'production'
22 | },
23 | appProps
24 | );
25 |
26 | export default {
27 | // 这个字段走 app.json
28 | config: {
29 | pages: ['^pages/index/index', 'pages/sample/sample'], // 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
30 | window: {
31 | backgroundTextStyle: 'black',
32 | navigationBarBackgroundColor: '#ffffff',
33 | navigationBarTitleText: 'WeChat',
34 | navigationBarTextStyle: 'black'
35 | },
36 | tabBar: {
37 | color: '#69707E',
38 | selectedColor: '#69707E',
39 | backgroundColor: '#ffffff',
40 | list: [
41 | {
42 | pagePath: 'pages/index/index',
43 | text: '首页',
44 | iconPath: 'static/images/home.png',
45 | selectedIconPath: 'static/images/home-active.png'
46 | },
47 | {
48 | pagePath: 'pages/sample/sample',
49 | text: '我的',
50 | iconPath: 'static/images/uc.png',
51 | selectedIconPath: 'static/images/uc-active.png'
52 | }
53 | ]
54 | },
55 | networkTimeout: {
56 | request: 10000,
57 | downloadFile: 10000
58 | },
59 | debug: false
60 | }
61 | };
62 |
--------------------------------------------------------------------------------
/app/_archive/src/mocks/examples.json:
--------------------------------------------------------------------------------
1 | {
2 | "code": 200,
3 | "data": [
4 | {
5 | "title": "sample mpvue wxapp",
6 | "content": "this is a sample of mpvue wxapp project"
7 | },
8 | {
9 | "title": "sample mpvue wxapp2",
10 | "content": "this is a sample of mpvue wxapp project 2"
11 | }
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/index/index.less:
--------------------------------------------------------------------------------
1 | .container {
2 | position: relative;
3 | background-color: #e7e7e7;
4 | display: flex;
5 | flex-direction: column;
6 | height: 100vh;
7 | & > .section {
8 | flex-shrink: 0;
9 | flex-grow: 0;
10 | }
11 |
12 | .loader {
13 | text-align: center;
14 | margin: 100rpx auto;
15 | img {
16 | width: 60rpx;
17 | height: 60rpx;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
98 |
99 |
102 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/index/main.js:
--------------------------------------------------------------------------------
1 | import Page from './index';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | new WrapPage(Page, {
5 | state() {
6 | return {
7 | test: 1
8 | };
9 | },
10 | mutations: {
11 | updateTest(state, test) {
12 | state.test = test;
13 | }
14 | }
15 | });
16 |
17 | export default {
18 | config: {
19 | backgroundTextStyle: 'light',
20 | navigationBarBackgroundColor: '#00b2ff',
21 | navigationBarTitleText: '首页',
22 | navigationBarTextStyle: 'white'
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/sample/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
20 |
21 |
27 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/sample/main.js:
--------------------------------------------------------------------------------
1 | import Page from './index';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | new WrapPage(Page);
5 |
6 | export default {
7 | config: {
8 | backgroundTextStyle: 'black',
9 | navigationBarBackgroundColor: '#ffffff',
10 | navigationBarTitleText: '示例页面',
11 | navigationBarTextStyle: 'black'
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/webview/index.less:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/src/pages/webview/index.less
--------------------------------------------------------------------------------
/app/_archive/src/pages/webview/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
75 |
76 |
79 |
--------------------------------------------------------------------------------
/app/_archive/src/pages/webview/main.js:
--------------------------------------------------------------------------------
1 | import Page from './index';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | new WrapPage(Page);
5 |
6 | export default {
7 | config: {
8 | navigationBarTitleText: ''
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/app/_archive/src/store/main.js:
--------------------------------------------------------------------------------
1 | import { VuexStore } from 'common-mpvue';
2 |
3 | export default (function() {
4 | let store = null;
5 |
6 | return function createStore() {
7 | const initialState = Object.assign(Object.create(null), {
8 | examples: []
9 | });
10 | if (!store) {
11 | store = new VuexStore({
12 | strict: process.env.NODE_ENV !== 'production',
13 | state: initialState,
14 | mutations: {
15 | // examples
16 | updateExamples(state, examples) {
17 | state.examples = examples;
18 | }
19 | }
20 | });
21 | }
22 |
23 | return store;
24 | };
25 | })();
26 |
--------------------------------------------------------------------------------
/app/_archive/src/utils/index.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/src/utils/index.js
--------------------------------------------------------------------------------
/app/_archive/static/images/home-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/home-active.png
--------------------------------------------------------------------------------
/app/_archive/static/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/home.png
--------------------------------------------------------------------------------
/app/_archive/static/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/loading.gif
--------------------------------------------------------------------------------
/app/_archive/static/images/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/success.png
--------------------------------------------------------------------------------
/app/_archive/static/images/uc-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/uc-active.png
--------------------------------------------------------------------------------
/app/_archive/static/images/uc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/uc.png
--------------------------------------------------------------------------------
/app/_archive/static/images/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive/static/images/warn.png
--------------------------------------------------------------------------------
/app/_archive_ts.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts.zip
--------------------------------------------------------------------------------
/app/_archive_ts/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/_archive_ts/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/app/_archive_ts/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/app/_archive_ts/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
5 | extends: ['standard', 'plugin:vue/essential'],
6 | // add your custom rules here
7 | rules: {
8 | // allow debugger during development
9 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
10 |
11 | 'wrap-iife': 0,
12 |
13 | 'space-before-function-paren': 0,
14 |
15 | semi: [2, 'always'],
16 |
17 | 'no-new': 0,
18 |
19 | 'vue/mustache-interpolation-spacing': 0,
20 | indent: [
21 | 0,
22 | 4,
23 | {
24 | SwitchCase: 1,
25 | VariableDeclarator: 1,
26 | outerIIFEBody: 1,
27 | FunctionDeclaration: {
28 | parameters: 1,
29 | body: 1
30 | },
31 | FunctionExpression: {
32 | parameters: 1,
33 | body: 1
34 | }
35 | }
36 | ]
37 | },
38 | globals: {
39 | App: true,
40 | Page: true,
41 | wx: true,
42 | getApp: true,
43 | getPage: true,
44 | getCurrentPages: true
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/app/_archive_ts/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | .vscode/
61 | .dll/
62 | dist/
--------------------------------------------------------------------------------
/app/_archive_ts/.lintstagedrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | 'src/**/*.{ts,tsx}': ['lint-staged:format', 'lint-staged:ts', 'git add'],
3 | 'src/**/*.{js,vue}': ['lint-staged:format', 'lint-staged:js', 'git add']
4 | };
5 |
--------------------------------------------------------------------------------
/app/_archive_ts/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {},
7 | "postcss-mpvue-wxss": {}
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/app/_archive_ts/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/app/_archive_ts/.tslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["tslint-eslint-rules"],
3 | "rules": {
4 | "align": [true, "parameters", "statements"],
5 | "class-name": true,
6 | "comment-format": [true, "check-space"],
7 | "curly": true,
8 | "object-curly-spacing": true,
9 | "eofline": true,
10 | "forin": true,
11 | "indent": [true, "spaces"],
12 | "jsdoc-format": false,
13 | "label-position": true,
14 | "max-line-length": [false, 120],
15 | "member-ordering": [
16 | false,
17 | {
18 | "order": "statics-first"
19 | }
20 | ],
21 | "new-parens": true,
22 | "no-any": false,
23 | "no-arg": true,
24 | "no-bitwise": true,
25 | "no-conditional-assignment": true,
26 | "no-consecutive-blank-lines": true,
27 | "no-console": [
28 | true,
29 | "debug",
30 | "info",
31 | "log",
32 | "time",
33 | "timeEnd",
34 | "trace"
35 | ],
36 | "no-construct": true,
37 | "no-constructor-vars": false,
38 | "no-debugger": true,
39 | "no-duplicate-variable": true,
40 | "no-empty": false,
41 | "no-eval": true,
42 | "no-internal-module": true,
43 | "no-namespace": true,
44 | "no-reference": true,
45 | "no-shadowed-variable": true,
46 | "no-string-literal": true,
47 | "no-switch-case-fall-through": false,
48 | "no-trailing-whitespace": true,
49 | "no-unused-expression": true,
50 | "no-use-before-declare": false,
51 | "no-var-keyword": true,
52 | "no-var-requires": false,
53 | "object-literal-sort-keys": false,
54 | "one-line": [
55 | true,
56 | "check-catch",
57 | "check-else",
58 | "check-finally",
59 | "check-open-brace",
60 | "check-whitespace"
61 | ],
62 | "one-variable-per-declaration": [true, "ignore-for-loop"],
63 | "quotemark": [true, "double", "jsx-double"],
64 | "radix": true,
65 | "semicolon": [true, "always", "ignore-bound-class-methods"],
66 | "switch-default": true,
67 | "trailing-comma": [
68 | true,
69 | {
70 | "singleline": "never",
71 | "multiline": "never"
72 | }
73 | ],
74 | "triple-equals": [true, "allow-null-check"],
75 | "typedef": false,
76 | "typedef-whitespace": [
77 | true,
78 | {
79 | "call-signature": "nospace",
80 | "index-signature": "nospace",
81 | "parameter": "nospace",
82 | "property-declaration": "nospace",
83 | "variable-declaration": "nospace"
84 | },
85 | {
86 | "call-signature": "onespace",
87 | "index-signature": "onespace",
88 | "parameter": "onespace",
89 | "property-declaration": "onespace",
90 | "variable-declaration": "onespace"
91 | }
92 | ],
93 | "use-isnan": true,
94 | "variable-name": [
95 | true,
96 | "allow-leading-underscore",
97 | "ban-keywords",
98 | "check-format",
99 | "allow-pascal-case"
100 | ],
101 | "whitespace": [
102 | true,
103 | "check-branch",
104 | "check-decl",
105 | "check-operator",
106 | "check-separator",
107 | "check-type",
108 | "check-typecast"
109 | ]
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/_archive_ts/README.md:
--------------------------------------------------------------------------------
1 | ## 使用
2 |
3 | 开发
4 |
5 | ```js
6 | npm run dev
7 | ```
8 |
9 | 开发并本地 mock API
10 |
11 | ```js
12 | npm run dev:mock
13 | ```
14 |
15 | 生产打包
16 |
17 | ```js
18 | npm run build
19 | ```
20 |
21 | 快速添加新页面
22 |
23 | ```js
24 | npm run newpage
25 | ```
26 |
27 | ## common-mpvue
28 |
29 | [common-mpvue](https://github.com/thundernet8/common-mpvue)
30 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/build.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')();
2 |
3 | process.env.NODE_ENV = 'production';
4 |
5 | var ora = require('ora');
6 | var rm = require('rimraf');
7 | var path = require('path');
8 | var chalk = require('chalk');
9 | var webpack = require('webpack');
10 | var config = require('../config');
11 | var webpackConfig = require('./webpack.prod.conf');
12 | var depManager = require('./dep');
13 |
14 | var spinner = ora('building for production...');
15 | spinner.start();
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err;
19 | webpack(webpackConfig, function(err, stats) {
20 | spinner.stop();
21 | if (err) throw err;
22 | process.stdout.write(
23 | stats.toString({
24 | colors: true,
25 | modules: false,
26 | children: false,
27 | chunks: false,
28 | chunkModules: false
29 | }) + '\n\n'
30 | );
31 |
32 | if (stats.hasErrors()) {
33 | console.log(chalk.red(' Build failed with errors.\n'));
34 | process.exit(1);
35 | }
36 |
37 | depManager.scanDeps();
38 |
39 | console.log(chalk.cyan(' Build complete.\n'));
40 | console.log(
41 | chalk.yellow(
42 | ' Tip: built files are meant to be served over an HTTP server.\n' +
43 | " Opening index.html over file:// won't work.\n"
44 | )
45 | );
46 | });
47 | });
48 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/check-versions.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk');
2 | var semver = require('semver');
3 | var packageConfig = require('../package.json');
4 | var shell = require('shelljs');
5 | function exec(cmd) {
6 | return require('child_process')
7 | .execSync(cmd)
8 | .toString()
9 | .trim();
10 | }
11 |
12 | var versionRequirements = [
13 | {
14 | name: 'node',
15 | currentVersion: semver.clean(process.version),
16 | versionRequirement: packageConfig.engines.node
17 | }
18 | ];
19 |
20 | if (shell.which('npm')) {
21 | versionRequirements.push({
22 | name: 'npm',
23 | currentVersion: exec('npm --version'),
24 | versionRequirement: packageConfig.engines.npm
25 | });
26 | }
27 |
28 | module.exports = function() {
29 | var warnings = [];
30 | for (var i = 0; i < versionRequirements.length; i++) {
31 | var mod = versionRequirements[i];
32 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
33 | warnings.push(
34 | mod.name +
35 | ': ' +
36 | chalk.red(mod.currentVersion) +
37 | ' should be ' +
38 | chalk.green(mod.versionRequirement)
39 | );
40 | }
41 | }
42 |
43 | if (warnings.length) {
44 | console.log('');
45 | console.log(
46 | chalk.yellow(
47 | 'To use this template, you must update following to modules:'
48 | )
49 | );
50 | console.log();
51 | for (var i = 0; i < warnings.length; i++) {
52 | var warning = warnings[i];
53 | console.log(' ' + warning);
54 | }
55 | console.log();
56 | process.exit(1);
57 | }
58 | };
59 |
--------------------------------------------------------------------------------
/app/_archive_ts/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 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/genPage.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const path = require('path');
3 | const inquirer = require('inquirer');
4 | const prettier = require('prettier');
5 | const prettierBaseConfig = {
6 | tabWidth: 4,
7 | useTabs: false,
8 | singleQuote: false,
9 | bracketSpacing: true
10 | };
11 | const prettierJsonConfig = Object.assign({}, prettierBaseConfig, {
12 | parser: 'json'
13 | });
14 | const prettierJsConfig = Object.assign({}, prettierBaseConfig, {
15 | parser: 'typescript'
16 | });
17 | const prettierCssConfig = Object.assign({}, prettierBaseConfig, {
18 | parser: 'css'
19 | });
20 |
21 | const PAGES_ROOT = path.resolve(process.cwd(), 'src/pages');
22 |
23 | const isTsProject = fs.existsSync(path.resolve(process.cwd(), 'src/main.ts'));
24 |
25 | function promptForPage() {
26 | const pages = fs.readdirSync(PAGES_ROOT).map(page => page.toLowerCase());
27 | const question = {
28 | type: 'input',
29 | name: 'page',
30 | message: '输入要新建的page',
31 | default: '',
32 | validate(input) {
33 | return new Promise((resolve, reject) => {
34 | input = String.prototype.toLowerCase.call(input);
35 | if (!input) {
36 | reject(new Error('请输入Page的名称'));
37 | } else if (pages.includes(input)) {
38 | reject(new Error('该Page已存在'));
39 | } else if (!/^[a-z]+$/i.test(input)) {
40 | reject(new Error('Page的名称必须为a-z组成'));
41 | }
42 | resolve(true);
43 | });
44 | }
45 | };
46 |
47 | return inquirer
48 | .prompt(question)
49 | .then(answer => String.prototype.toLowerCase.call(answer.page));
50 | }
51 |
52 | function addPage(page) {
53 | const pageFolder = path.resolve(PAGES_ROOT, page);
54 | fs.mkdirSync(pageFolder);
55 | // style
56 | const less = `.wrapper {position: relative;}`;
57 | fs.writeFileSync(
58 | path.resolve(pageFolder, 'index.less'),
59 | prettier.format(less, prettierCssConfig)
60 | );
61 | // main.js/ts
62 | if (!isTsProject) {
63 | const mainJs = `import Page from './index';
64 | import { WrapPage } from 'common-mpvue';
65 |
66 | new WrapPage(Page);
67 |
68 | export default {
69 | config: {
70 | backgroundTextStyle: 'black',
71 | navigationBarBackgroundColor: '#ffffff',
72 | navigationBarTitleText: '页面标题',
73 | navigationBarTextStyle: 'black'
74 | }
75 | };
76 | `;
77 | fs.writeFileSync(
78 | path.resolve(pageFolder, 'main.js'),
79 | prettier.format(mainJs, prettierJsConfig)
80 | );
81 | } else {
82 | const mainJs = `import Page from "./index.vue";
83 | import { WrapPage } from "common-mpvue";
84 |
85 | /* tslint:disable */
86 | new WrapPage(Page);
87 | /* tslint:enable */
88 |
89 | export default {
90 | config: {
91 | backgroundTextStyle: "black",
92 | navigationBarBackgroundColor: "#ffffff",
93 | navigationBarTitleText: "页面标题",
94 | navigationBarTextStyle: "black"
95 | }
96 | };
97 | `;
98 | fs.writeFileSync(
99 | path.resolve(pageFolder, 'main.ts'),
100 | prettier.format(mainJs, prettierJsConfig)
101 | );
102 | }
103 | // index.vue
104 | let vue;
105 | if (!isTsProject) {
106 | vue = `
107 |
108 | 页面${page}
109 |
110 |
111 |
112 |
126 |
127 |
130 | `;
131 | } else {
132 | vue = `
133 |
134 | 页面${page}
135 |
136 |
137 |
138 |
139 |
140 |
143 | `;
144 | }
145 | fs.writeFileSync(path.resolve(pageFolder, 'index.vue'), vue);
146 |
147 | // index.ts
148 | if (isTsProject) {
149 | const className = page.split('').map((char, index) => {
150 | if (index === 0) {
151 | return char.toUpperCase();
152 | }
153 | return char.toLowerCase();
154 | }).join('');
155 | const tsScript = `import board from '@/components/board.vue';
156 | import { getApp, wx, wxp } from 'common-mpvue';
157 | import { Component } from 'vue-property-decorator';
158 | import Vue from 'vue';
159 |
160 | @Component({
161 | components: {
162 | board
163 | }
164 | })
165 | export default class ${className} extends Vue {
166 | // props
167 | text: string = '';
168 |
169 | // computed:
170 | get upperText() {
171 | return this.text.toUpperCase()
172 | }
173 |
174 | // method
175 | updateText(text: string) {
176 | this.text = text;
177 | }
178 |
179 | onLoad() {}
180 |
181 | onShow() {}
182 |
183 | onReady() {}
184 |
185 | onUnload() {}
186 | }
187 | `;
188 | fs.writeFileSync(
189 | path.resolve(pageFolder, 'index.ts'),
190 | prettier.format(tsScript, prettierJsConfig)
191 | );
192 | }
193 | }
194 |
195 | promptForPage().then(page => {
196 | addPage(page);
197 | });
198 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/mock.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const fs = require('fs');
3 |
4 | module.exports = function mock(req, res) {
5 | const reqPath = req.path.slice(1);
6 | const jsonPath = path.resolve(__dirname, '../src', `${reqPath}.json`);
7 | console.log(`[** mocks **]: use ${jsonPath}`);
8 | try {
9 | // TODO require有缓存,在运行过程中修改json不会生效,需要重启dev server
10 | // TODO fs.readFileSync
11 | // const json = require(jsonPath);
12 | const json = fs.readFileSync(jsonPath).toString();
13 | res.json(JSON.parse(json));
14 | } catch (e) {
15 | if (e.message && e.message.indexOf('no such file or directory') > -1) {
16 | console.log('Mock json file not found');
17 | // res.json(JSON.stringify({}));
18 | res.status(404).end(`Mock json file not found: ${jsonPath}`);
19 | return;
20 | }
21 | throw e;
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/app/_archive_ts/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 =
7 | process.env.NODE_ENV === 'production'
8 | ? config.build.assetsSubDirectory
9 | : config.dev.assetsSubDirectory;
10 | return path.posix.join(assetsSubDirectory, _path);
11 | };
12 |
13 | exports.cssLoaders = function(options) {
14 | options = options || {};
15 |
16 | var cssLoader = {
17 | loader: 'css-loader',
18 | options: {
19 | minimize: process.env.NODE_ENV === 'production',
20 | sourceMap: options.sourceMap
21 | }
22 | };
23 |
24 | var postcssLoader = {
25 | loader: 'postcss-loader',
26 | options: {
27 | sourceMap: true
28 | }
29 | };
30 |
31 | var px2rpxLoader = {
32 | loader: 'px2rpx-loader',
33 | options: {
34 | baseDpr: 1,
35 | rpxUnit: 0.5
36 | }
37 | };
38 |
39 | // generate loader string to be used with extract text plugin
40 | function generateLoaders(loader, loaderOptions) {
41 | var loaders = [cssLoader, postcssLoader, px2rpxLoader];
42 | if (loader) {
43 | loaders.push({
44 | loader: loader + '-loader',
45 | options: Object.assign({}, loaderOptions, {
46 | sourceMap: options.sourceMap
47 | })
48 | });
49 | }
50 |
51 | // Extract CSS when that option is specified
52 | // (which is the case during production build)
53 | if (options.extract) {
54 | return ExtractTextPlugin.extract({
55 | use: loaders,
56 | fallback: 'vue-style-loader'
57 | });
58 | } else {
59 | return ['vue-style-loader'].concat(loaders);
60 | }
61 | }
62 |
63 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
64 | return {
65 | css: generateLoaders(),
66 | postcss: generateLoaders(),
67 | less: generateLoaders('less'),
68 | sass: generateLoaders('sass', { indentedSyntax: true }),
69 | scss: generateLoaders('sass'),
70 | stylus: generateLoaders('stylus'),
71 | styl: generateLoaders('stylus')
72 | };
73 | };
74 |
75 | // Generate loaders for standalone style files (outside of .vue)
76 | exports.styleLoaders = function(options) {
77 | var output = [];
78 | var loaders = exports.cssLoaders(options);
79 | for (var extension in loaders) {
80 | var loader = loaders[extension];
81 | output.push({
82 | test: new RegExp('\\.' + extension + '$'),
83 | use: loader
84 | });
85 | }
86 | return output;
87 | };
88 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var config = require('../config');
3 | // var isProduction = process.env.NODE_ENV === 'production'
4 | // for mp
5 | var isProduction = true;
6 |
7 | module.exports = {
8 | loaders: utils.cssLoaders({
9 | sourceMap: isProduction
10 | ? config.build.productionSourceMap
11 | : config.dev.cssSourceMap,
12 | extract: isProduction
13 | }),
14 | transformToRequire: {
15 | video: 'src',
16 | source: 'src',
17 | img: 'src',
18 | image: 'xlink:href'
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var webpack = require('webpack');
3 | var config = require('../config');
4 | var merge = require('webpack-merge');
5 | var baseWebpackConfig = require('./webpack.base.conf');
6 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
8 |
9 | // copy from ./webpack.prod.conf.js
10 | var path = require('path');
11 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
12 | var CopyWebpackPlugin = require('copy-webpack-plugin');
13 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
14 |
15 | // add hot-reload related code to entry chunks
16 | // Object.keys(baseWebpackConfig.entry).forEach(function (name) {
17 | // baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
18 | // })
19 |
20 | module.exports = merge(baseWebpackConfig, {
21 | module: {
22 | rules: utils.styleLoaders({
23 | sourceMap: config.dev.cssSourceMap,
24 | extract: true
25 | })
26 | },
27 | // cheap-module-eval-source-map is faster for development
28 | // devtool: '#cheap-module-eval-source-map',
29 | devtool: '#source-map',
30 | output: {
31 | path: config.build.assetsRoot,
32 | // filename: utils.assetsPath('js/[name].[chunkhash].js'),
33 | // chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
34 | filename: utils.assetsPath('js/[name].js'),
35 | chunkFilename: utils.assetsPath('js/[id].js')
36 | },
37 | plugins: [
38 | new webpack.DefinePlugin({
39 | 'process.env': config.dev.env
40 | }),
41 |
42 | // copy from ./webpack.prod.conf.js
43 | // extract css into its own file
44 | new ExtractTextPlugin({
45 | // filename: utils.assetsPath('css/[name].[contenthash].css')
46 | filename: utils.assetsPath('css/[name].wxss')
47 | }),
48 | // Compress extracted CSS. We are using this plugin so that possible
49 | // duplicated CSS from different components can be deduped.
50 | new OptimizeCSSPlugin({
51 | cssProcessorOptions: {
52 | safe: true
53 | }
54 | }),
55 | new webpack.optimize.CommonsChunkPlugin({
56 | name: 'vendor',
57 | minChunks: function(module, count) {
58 | // any required modules inside node_modules are extracted to vendor
59 | return (
60 | module.resource &&
61 | /\.js$/.test(module.resource) &&
62 | module.resource.indexOf('node_modules') >= 0
63 | );
64 | }
65 | }),
66 | new webpack.optimize.CommonsChunkPlugin({
67 | name: 'manifest',
68 | chunks: ['vendor']
69 | }),
70 | // copy custom static assets
71 | new CopyWebpackPlugin([
72 | {
73 | from: path.resolve(__dirname, '../static'),
74 | to: config.build.assetsSubDirectory,
75 | ignore: ['.*']
76 | }
77 | ]),
78 |
79 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
80 | // new webpack.HotModuleReplacementPlugin(),
81 | new webpack.NoEmitOnErrorsPlugin(),
82 | // https://github.com/ampedandwired/html-webpack-plugin
83 | // new HtmlWebpackPlugin({
84 | // filename: 'index.html',
85 | // template: 'index.html',
86 | // inject: true
87 | // }),
88 | new FriendlyErrorsPlugin()
89 | ]
90 | });
91 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/webpack.dll.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var config = require('../config');
3 | var webpack = require('webpack');
4 |
5 | function resolve(dir) {
6 | return path.join(__dirname, '..', dir);
7 | }
8 |
9 | const plugins = [];
10 | if (config.build.bundleAnalyzerReport) {
11 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
12 | .BundleAnalyzerPlugin;
13 | plugins.push(new BundleAnalyzerPlugin());
14 | }
15 |
16 | module.exports = {
17 | entry: {
18 | dll: [
19 | 'mpvue',
20 | 'vuex',
21 | 'common-mpvue',
22 | 'querystring',
23 | 'url-parse',
24 | 'md5',
25 | 'left-pad',
26 | 'date-fns'
27 | ]
28 | },
29 | output: {
30 | path: path.resolve(__dirname, '../dist'), //config.build.assetsRoot,
31 | filename:
32 | process.env.NODE_ENV === 'production' ? 'dll.js' : 'dll-dev.js',
33 | publicPath:
34 | process.env.NODE_ENV === 'production'
35 | ? config.build.assetsPublicPath
36 | : config.dev.assetsPublicPath,
37 | library: 'dll',
38 | libraryTarget: 'commonjs2'
39 | },
40 | resolve: {
41 | extensions: ['.js', '.json'],
42 | alias: {
43 | vue: 'mpvue',
44 | '@': resolve('src')
45 | },
46 | symlinks: false
47 | },
48 | module: {
49 | rules: [
50 | {
51 | test: /\.js$/,
52 | include: [resolve('src'), resolve('test')],
53 | use: ['babel-loader']
54 | }
55 | ]
56 | },
57 | plugins: [
58 | ...plugins,
59 | new webpack.DllPlugin({
60 | context: __dirname,
61 | path: '.dll/manifest.json',
62 | name: '[name]'
63 | }),
64 | new webpack.HashedModuleIdsPlugin()
65 | // new webpack.optimize.UglifyJsPlugin({
66 | // compress: {
67 | // warnings: false
68 | // },
69 | // sourceMap: false
70 | // })
71 | ]
72 | };
73 |
--------------------------------------------------------------------------------
/app/_archive_ts/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var utils = require('./utils');
3 | var webpack = require('webpack');
4 | var config = require('../config');
5 | var merge = require('webpack-merge');
6 | var baseWebpackConfig = require('./webpack.base.conf');
7 | var CopyWebpackPlugin = require('copy-webpack-plugin');
8 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
9 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
11 | var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
12 |
13 | var env = config.build.env;
14 |
15 | var webpackConfig = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({
18 | sourceMap: config.build.productionSourceMap,
19 | extract: true
20 | })
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 | filename: utils.assetsPath('js/[name].js'),
28 | chunkFilename: utils.assetsPath('js/[id].js')
29 | },
30 | plugins: [
31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
32 | new webpack.DefinePlugin({
33 | 'process.env': env
34 | }),
35 | new UglifyJsPlugin({
36 | sourceMap: true
37 | }),
38 | // extract css into its own file
39 | new ExtractTextPlugin({
40 | // filename: utils.assetsPath('css/[name].[contenthash].css')
41 | filename: utils.assetsPath('css/[name].wxss')
42 | }),
43 | // Compress extracted CSS. We are using this plugin so that possible
44 | // duplicated CSS from different components can be deduped.
45 | new OptimizeCSSPlugin({
46 | cssProcessorOptions: {
47 | safe: true
48 | }
49 | }),
50 | // generate dist index.html with correct asset hash for caching.
51 | // you can customize output by editing /index.html
52 | // see https://github.com/ampedandwired/html-webpack-plugin
53 | // new HtmlWebpackPlugin({
54 | // filename: config.build.index,
55 | // template: 'index.html',
56 | // inject: true,
57 | // minify: {
58 | // removeComments: true,
59 | // collapseWhitespace: true,
60 | // removeAttributeQuotes: true
61 | // // more options:
62 | // // https://github.com/kangax/html-minifier#options-quick-reference
63 | // },
64 | // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
65 | // chunksSortMode: 'dependency'
66 | // }),
67 | // keep module.id stable when vender modules does not change
68 | new webpack.HashedModuleIdsPlugin(),
69 | // split vendor js into its own file
70 | new webpack.optimize.CommonsChunkPlugin({
71 | name: 'vendor',
72 | minChunks: function(module, count) {
73 | // any required modules inside node_modules are extracted to vendor
74 | return (
75 | module.resource &&
76 | /\.js$/.test(module.resource) &&
77 | module.resource.indexOf('node_modules') >= 0
78 | );
79 | }
80 | }),
81 | // extract webpack runtime and module manifest to its own file in order to
82 | // prevent vendor hash from being updated whenever app bundle is updated
83 | new webpack.optimize.CommonsChunkPlugin({
84 | name: 'manifest',
85 | chunks: ['vendor']
86 | }),
87 | // copy custom static assets
88 | new CopyWebpackPlugin([
89 | {
90 | from: path.resolve(__dirname, '../static'),
91 | to: config.build.assetsSubDirectory,
92 | ignore: ['.*']
93 | }
94 | ])
95 | ]
96 | });
97 |
98 | // if (config.build.productionGzip) {
99 | // var CompressionWebpackPlugin = require('compression-webpack-plugin')
100 |
101 | // webpackConfig.plugins.push(
102 | // new CompressionWebpackPlugin({
103 | // asset: '[path].gz[query]',
104 | // algorithm: 'gzip',
105 | // test: new RegExp(
106 | // '\\.(' +
107 | // config.build.productionGzipExtensions.join('|') +
108 | // ')$'
109 | // ),
110 | // threshold: 10240,
111 | // minRatio: 0.8
112 | // })
113 | // )
114 | // }
115 |
116 | if (config.build.bundleAnalyzerReport) {
117 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
118 | .BundleAnalyzerPlugin;
119 | webpackConfig.plugins.push(new BundleAnalyzerPlugin());
120 | }
121 |
122 | module.exports = webpackConfig;
123 |
--------------------------------------------------------------------------------
/app/_archive_ts/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 | PORT: 8080,
7 | MOCK: process.env.MOCK,
8 | PKG_TYPE: process.env.PKG_TYPE
9 | });
10 |
--------------------------------------------------------------------------------
/app/_archive_ts/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path');
3 | var env = require('./dev.env');
4 |
5 | module.exports = {
6 | build: {
7 | env: require('./prod.env'),
8 | index: path.resolve(__dirname, '../dist/index.html'),
9 | assetsRoot: path.resolve(__dirname, '../dist'),
10 | assetsSubDirectory: 'static',
11 | assetsPublicPath: '/',
12 | productionSourceMap: false,
13 | // Gzip off by default as many popular static hosts such as
14 | // Surge or Netlify already gzip all static assets for you.
15 | // Before setting to `true`, make sure to:
16 | // npm install --save-dev compression-webpack-plugin
17 | productionGzip: false,
18 | productionGzipExtensions: ['js', 'css'],
19 | // Run the build command with an extra argument to
20 | // View the bundle analyzer report after build finishes:
21 | // `npm run build --report`
22 | // Set to `true` or `false` to always turn it on or off
23 | bundleAnalyzerReport: process.env.npm_config_report
24 | },
25 | dev: {
26 | env,
27 | port: env.PORT,
28 | // 在小程序开发者工具中不需要自动打开浏览器
29 | autoOpenBrowser: false,
30 | assetsSubDirectory: 'static',
31 | assetsPublicPath: '/',
32 | proxyTable: {},
33 | // CSS Sourcemaps off by default because relative paths are "buggy"
34 | // with this option, according to the CSS-Loader README
35 | // (https://github.com/webpack/css-loader#sourcemaps)
36 | // In our experience, they generally work as expected,
37 | // just be aware of this issue when enabling this option.
38 | cssSourceMap: false
39 | }
40 | };
41 |
--------------------------------------------------------------------------------
/app/_archive_ts/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | };
4 |
--------------------------------------------------------------------------------
/app/_archive_ts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sample-mpvue-wxapp",
3 | "version": "1.0.0",
4 | "description": "example project of miniprogram developed via mpvue",
5 | "private": true,
6 | "scripts": {
7 | "lint-staged": "lint-staged -c .lintstagedrc.js",
8 | "lint": "npm run lint:js && npm run lint:ts",
9 | "lint:js": "eslint --fix --ext .js,.vue src",
10 | "lint:ts": "tslint -e node_modules --fix -c .tslintrc.json src/**/*.ts",
11 | "lint-staged:js": "eslint --fix -c .eslintrc.js",
12 | "lint-staged:ts": "tslint --fix -c .tslintrc.json",
13 | "lint-staged:format": "prettier --write",
14 | "format":
15 | "prettier --write --tab-width 4 --single-quote true --stdin-filepath src/**/*.{less,vue,js}",
16 | "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
17 | "dll":
18 | "cross-env NODE_ENV=production webpack -p --hide-modules --config build/webpack.dll.conf.js",
19 | "dll:dev":
20 | "cross-env NODE_ENV=development webpack --hide-modules --config build/webpack.dll.conf.js",
21 | "dll:report":
22 | "cross-env npm_config_report=true NODE_ENV=production webpack --hide-modules --config build/webpack.dll.conf.js",
23 | "dev": "node build/dev-server.js",
24 | "dev:mock": "cross-env MOCK=true node build/dev-server.js",
25 | "start": "npm run dll:dev && node build/dev-server.js",
26 | "build": " rimraf dist && npm run dll && node build/build.js",
27 | "build:report":
28 | "rimraf dist && npm run dll && cross-env npm_config_report=true node build/build.js",
29 | "newpage": "node build/genPage.js"
30 | },
31 | "dependencies": {
32 | "@types/node": "^9.6.2",
33 | "common-mpvue": "latest",
34 | "date-fns": "^1.29.0",
35 | "left-pad": "^1.2.0",
36 | "md5": "^2.2.1",
37 | "mpvue": "^1.0.12",
38 | "querystring": "^0.2.0",
39 | "url-parse": "^1.2.0",
40 | "vue-property-decorator": "^6.0.0",
41 | "vuex": "^3.0.1"
42 | },
43 | "devDependencies": {
44 | "autoprefixer": "^7.1.2",
45 | "babel-core": "^6.22.1",
46 | "babel-eslint": "^7.1.1",
47 | "babel-loader": "^7.1.1",
48 | "babel-plugin-module-resolver": "^3.1.1",
49 | "babel-plugin-transform-runtime": "^6.22.0",
50 | "babel-preset-env": "^1.3.2",
51 | "babel-preset-stage-2": "^6.22.0",
52 | "babel-register": "^6.22.0",
53 | "chalk": "^2.0.1",
54 | "chokidar": "^2.0.2",
55 | "connect-history-api-fallback": "^1.3.0",
56 | "copy-webpack-plugin": "^4.5.1",
57 | "cross-env": "^5.1.4",
58 | "css-loader": "^0.28.0",
59 | "cssnano": "^3.10.0",
60 | "eslint": "^4.19.1",
61 | "eslint-config-standard": "^11.0.0",
62 | "eslint-friendly-formatter": "^3.0.0",
63 | "eslint-loader": "^1.7.1",
64 | "eslint-plugin-html": "^3.0.0",
65 | "eslint-plugin-import": "^2.10.0",
66 | "eslint-plugin-node": "^6.0.1",
67 | "eslint-plugin-promise": "^3.4.0",
68 | "eslint-plugin-standard": "^2.0.1",
69 | "eslint-plugin-vue": "^4.4.0",
70 | "eventsource-polyfill": "^0.9.6",
71 | "express": "^4.14.1",
72 | "extract-text-webpack-plugin": "^2.0.0",
73 | "file-loader": "^0.11.1",
74 | "friendly-errors-webpack-plugin": "^1.1.3",
75 | "html-webpack-plugin": "^2.28.0",
76 | "http-proxy-middleware": "^0.17.3",
77 | "koa": "^2.5.0",
78 | "less": "^3.0.1",
79 | "less-loader": "^4.1.0",
80 | "lint-staged": "^6.1.1",
81 | "mkdirp": "^0.5.1",
82 | "mpvue-loader": "^1.0.14",
83 | "mpvue-template-compiler": "^1.0.12",
84 | "mpvue-ts-loader": "^1.0.13",
85 | "mpvue-webpack-target": "^1.0.0",
86 | "opn": "^5.1.0",
87 | "optimize-css-assets-webpack-plugin": "^2.0.0",
88 | "ora": "^1.2.0",
89 | "postcss-loader": "^2.0.6",
90 | "postcss-mpvue-wxss": "^1.0.0",
91 | "pre-commit": "^1.2.2",
92 | "prettier": "^1.11.1",
93 | "px2rpx-loader": "^0.1.8",
94 | "replace-ext": "^1.0.0",
95 | "resolve": "^1.7.1",
96 | "rimraf": "^2.6.2",
97 | "semver": "^5.3.0",
98 | "shelljs": "^0.7.6",
99 | "string-replace-webpack-plugin": "^0.1.3",
100 | "stylelint": "^9.1.3",
101 | "ts-loader": "^3.5.0",
102 | "tslint": "^5.9.1",
103 | "tslint-eslint-rules": "^5.1.0",
104 | "typescript": "^2.8.1",
105 | "uglifyjs-webpack-plugin": "^1.2.4",
106 | "url-loader": "^0.5.8",
107 | "vue": "^2.5.16",
108 | "vue-style-loader": "^3.0.1",
109 | "webpack": "^2.6.1",
110 | "webpack-bundle-analyzer": "^2.2.1",
111 | "webpack-dev-middleware": "^1.10.0",
112 | "webpack-dev-middleware-hard-disk": "^1.10.0",
113 | "webpack-hot-middleware": "^2.18.0",
114 | "webpack-merge": "^4.1.0",
115 | "webpack-mpvue-asset-plugin": "^0.0.2"
116 | },
117 | "engines": {
118 | "node": ">= 4.0.0",
119 | "npm": ">= 3.0.0"
120 | },
121 | "browserslist": ["> 1%", "last 2 versions", "not ie <= 8"],
122 | "pre-commit": ["precommit-msg", "lint-staged"]
123 | }
124 |
--------------------------------------------------------------------------------
/app/_archive_ts/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": false,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "compileType": "miniprogram",
11 | "libVersion": "1.9.93",
12 | "appid": "",
13 | "projectname": "sample-mpvue-wxapp",
14 | "isGameTourist": false,
15 | "condition": {
16 | "search": {
17 | "current": -1,
18 | "list": []
19 | },
20 | "conversation": {
21 | "current": -1,
22 | "list": []
23 | },
24 | "game": {
25 | "currentL": -1,
26 | "list": []
27 | },
28 | "miniprogram": {
29 | "current": -1,
30 | "list": []
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/App.vue:
--------------------------------------------------------------------------------
1 |
29 |
30 |
33 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/api/home.ts:
--------------------------------------------------------------------------------
1 | import { wx } from 'common-mpvue';
2 |
3 | const httpRequest = wx.httpRequest
4 | .auth()
5 | .tokenKey('token')
6 | .qsToken();
7 |
8 | // 示例请求
9 | export function exampleRequest() {
10 | return httpRequest.GET('/examples');
11 | }
12 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/assets/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/src/assets/images/loading.gif
--------------------------------------------------------------------------------
/app/_archive_ts/src/assets/styles/global.less:
--------------------------------------------------------------------------------
1 | .container {
2 | font-family: 'Microsoft YaHei', Helvetica, STHeiTi, sans-seri;
3 | position: relative;
4 | background-color: #e7e7e7;
5 | display: flex;
6 | flex-direction: column;
7 | min-height: 100vh;
8 | & > .section {
9 | flex-shrink: 0;
10 | flex-grow: 0;
11 | }
12 | .placeholder-container {
13 | flex: 1;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/common/_app.ts:
--------------------------------------------------------------------------------
1 | // 扩展app实例的方法和属性
2 | export default {
3 | getName() {
4 | return this.name;
5 | }
6 | };
7 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/components/board.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{title}}
4 |
{{content}}
5 |
6 |
7 |
8 |
25 |
26 |
42 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/config/index.ts:
--------------------------------------------------------------------------------
1 | const DOMAIN_MAP = {
2 | development: process.env.MOCK
3 | ? `http://localhost:${process.env.PORT}/mocks`
4 | : 'http://beta.example.com',
5 | beta: 'http://beta.example.com',
6 | production: 'https://api.example.com'
7 | };
8 |
9 | export default {
10 | VERSION: '1.0.0',
11 | APP_NAME: 'sample-mpvue-wxapp',
12 | MOCK: process.env.MOCK && process.env.MOCK.toString() === 'true',
13 | DEBUG: process.env.NODE_ENV !== 'production',
14 | DOMAIN:
15 | DOMAIN_MAP[process.env.NODE_ENV || 'production'] ||
16 | 'https://api.example.com'
17 | };
18 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/main.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import { Component } from 'vue-property-decorator';
3 | import App from './App.vue';
4 | import { wrap, wx } from 'common-mpvue';
5 | import config from './config';
6 | import appProps from './common/_app';
7 |
8 | const pkg = require('../package.json');
9 |
10 | // 设置wx debug模式
11 | if (process.env.NODE_ENV !== 'production') {
12 | wx.setEnableDebug({ enableDebug: true });
13 | }
14 |
15 | Vue.config.productionTip = false;
16 | // 添加小程序hooks http://mpvue.com/mpvue/#_4
17 | Component.registerHooks([
18 | // pages
19 | 'onLoad', // 监听页面加载
20 | 'onShow', // 监听页面显示
21 | 'onReady', // 监听页面初次渲染完成
22 | 'onHide', // 监听页面隐藏
23 | 'onUnload', // 监听页面卸载
24 | 'onPullDownRefresh', // 监听用户下拉动作
25 | 'onReachBottom', // 页面上拉触底事件的处理函数
26 | 'onShareAppMessage', // 用户点击右上角分享
27 | 'onPageScroll', // 页面滚动
28 | 'onTabItemTap' //当前是 tab 页时 // 点击 tab 时触发 (mpvue 0.0.16 支持)
29 | ]);
30 |
31 | wrap(
32 | App,
33 | {
34 | name: config.APP_NAME,
35 | version: config.VERSION,
36 | pkgName: pkg.name,
37 | domain: config.DOMAIN,
38 | env: config.DEBUG ? 'development' : 'production'
39 | },
40 | appProps
41 | );
42 |
43 | export default {
44 | // 这个字段走 app.json
45 | config: {
46 | pages: ['^pages/index/index', 'pages/sample/sample'], // 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
47 | window: {
48 | backgroundTextStyle: 'black',
49 | navigationBarBackgroundColor: '#ffffff',
50 | navigationBarTitleText: 'WeChat',
51 | navigationBarTextStyle: 'black'
52 | },
53 | tabBar: {
54 | color: '#69707E',
55 | selectedColor: '#69707E',
56 | backgroundColor: '#ffffff',
57 | list: [
58 | {
59 | pagePath: 'pages/index/index',
60 | text: '首页',
61 | iconPath: 'static/images/home.png',
62 | selectedIconPath: 'static/images/home-active.png'
63 | },
64 | {
65 | pagePath: 'pages/sample/sample',
66 | text: '示例1',
67 | iconPath: 'static/images/uc.png',
68 | selectedIconPath: 'static/images/uc-active.png'
69 | },
70 | {
71 | pagePath: 'pages/sample2/sample2',
72 | text: '示例2',
73 | iconPath: 'static/images/uc.png',
74 | selectedIconPath: 'static/images/uc-active.png'
75 | }
76 | ]
77 | },
78 | networkTimeout: {
79 | request: 10000,
80 | downloadFile: 10000
81 | },
82 | debug: false
83 | }
84 | };
85 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/mocks/examples.json:
--------------------------------------------------------------------------------
1 | {
2 | "code": 200,
3 | "data": [
4 | {
5 | "title": "sample mpvue wxapp",
6 | "content": "this is a sample of mpvue wxapp project"
7 | },
8 | {
9 | "title": "sample mpvue wxapp2",
10 | "content": "this is a sample of mpvue wxapp project 2"
11 | }
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/index/index.less:
--------------------------------------------------------------------------------
1 | .container {
2 | position: relative;
3 | background-color: #e7e7e7;
4 | display: flex;
5 | flex-direction: column;
6 | height: 100vh;
7 | & > .section {
8 | flex-shrink: 0;
9 | flex-grow: 0;
10 | }
11 |
12 | .loader {
13 | text-align: center;
14 | margin: 100rpx auto;
15 | img {
16 | width: 60rpx;
17 | height: 60rpx;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
99 |
100 |
103 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/index/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page, {
6 | state() {
7 | return {
8 | test: 1
9 | };
10 | },
11 | mutations: {
12 | updateTest(state: any, test) {
13 | state.test = test;
14 | }
15 | }
16 | });
17 | /* tslint:enable */
18 |
19 | export default {
20 | config: {
21 | backgroundTextStyle: 'light',
22 | navigationBarBackgroundColor: '#00b2ff',
23 | navigationBarTitleText: '首页',
24 | navigationBarTextStyle: 'white'
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample/README.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | 本页面使用 Vue 默认的组件写法,导出 VueOptions 对象
4 |
5 | ```js
6 | export default {
7 | data() {
8 | return {}
9 | },
10 |
11 | ...
12 | }
13 | ```
14 |
15 | 同样可以使用`Vue.extend`写法,语法类似
16 |
17 | ```js
18 | import Vue from 'vue';
19 |
20 | export default Vue.extend({
21 | data() {
22 | return {};
23 | }
24 | });
25 | ```
26 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
20 |
21 |
27 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | backgroundTextStyle: 'black',
11 | navigationBarBackgroundColor: '#ffffff',
12 | navigationBarTitleText: '示例页面',
13 | navigationBarTextStyle: 'black'
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample2/README.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | 本页面使用 Vue Class 继承式组件写法
4 |
5 | ```js
6 | export default class Sample2 extends Vue {
7 | // ...
8 | }
9 | ```
10 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample2/index.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import { Component } from 'vue-property-decorator';
3 | import board from '@/components/board.vue';
4 |
5 | // 必须以Component装饰器模式指定子组件
6 | @Component({
7 | components: {
8 | board
9 | }
10 | })
11 | export default class Sample2 extends Vue {
12 | // 私有属性方式指定data元素
13 | title: string = '示例页面2';
14 | content: string = '使用TypeScript+Vue Class组件写法';
15 |
16 | // get 方法指定computed的元素
17 | get computed1() {
18 | return 'computed1';
19 | }
20 |
21 | // methods直接写为类方法
22 | method1() {
23 | // do something
24 | }
25 |
26 | // 小程序生命周期
27 | onShow() {
28 | console.log('[Sample2] onShow');
29 | }
30 |
31 | // Vue生命周期
32 | mounted() {
33 | console.log('[Sample2] mounted');
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample2/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
18 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/sample2/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | backgroundTextStyle: 'black',
11 | navigationBarBackgroundColor: '#ffffff',
12 | navigationBarTitleText: '示例页面2',
13 | navigationBarTextStyle: 'black'
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/webview/index.less:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/src/pages/webview/index.less
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/webview/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
77 |
78 |
81 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/pages/webview/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | navigationBarTitleText: ''
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/store/main.ts:
--------------------------------------------------------------------------------
1 | import { VuexStore } from 'common-mpvue';
2 |
3 | export default (function() {
4 | let store: VuexStore = null as any;
5 |
6 | return function createStore() {
7 | const initialState = Object.assign(Object.create(null), {
8 | examples: []
9 | });
10 | if (!store) {
11 | store = new VuexStore({
12 | strict: process.env.NODE_ENV !== 'production',
13 | state: initialState,
14 | mutations: {
15 | // examples
16 | updateExamples(state, examples) {
17 | state.examples = examples;
18 | }
19 | }
20 | });
21 | }
22 |
23 | return store;
24 | };
25 | })();
26 |
--------------------------------------------------------------------------------
/app/_archive_ts/src/utils/index.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/src/utils/index.ts
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/home-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/home-active.png
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/home.png
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/loading.gif
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/success.png
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/uc-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/uc-active.png
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/uc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/uc.png
--------------------------------------------------------------------------------
/app/_archive_ts/static/images/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/app/_archive_ts/static/images/warn.png
--------------------------------------------------------------------------------
/app/_archive_ts/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target":
4 | "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
5 | "module":
6 | "es2015" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7 | // "lib": [], /* Specify library files to be included in the compilation. */
8 | // "allowJs": true, /* Allow javascript files to be compiled. */
9 | // "checkJs": true, /* Report errors in .js files. */
10 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11 | // "declaration": true, /* Generates corresponding '.d.ts' file. */
12 | // "sourceMap": true, /* Generates corresponding '.map' file. */
13 | // "outFile": "./", /* Concatenate and emit output to single file. */
14 | // "outDir": "./", /* Redirect output structure to the directory. */
15 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16 | // "removeComments": true, /* Do not emit comments to output. */
17 | // "noEmit": true, /* Do not emit outputs. */
18 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */
19 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
20 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
21 |
22 | /* Strict Type-Checking Options */
23 | // "strict": true /* Enable all strict type-checking options. */,
24 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25 | "strictNullChecks": true /* Enable strict null checks. */,
26 | "strictFunctionTypes": true /* Enable strict checking of function types. */,
27 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
28 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
29 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
30 |
31 | /* Additional Checks */
32 | // "noUnusedLocals": true, /* Report errors on unused locals. */
33 | // "noUnusedParameters": true, /* Report errors on unused parameters. */
34 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36 |
37 | /* Module Resolution Options */
38 | "moduleResolution":
39 | "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
40 | "baseUrl":
41 | "src" /* Base directory to resolve non-absolute module names. */,
42 | "paths": {
43 | "@/api/*": ["api/*"],
44 | "@/common/*": ["common/*"],
45 | "@/components/*": ["components/*"],
46 | "@/assets/*": ["assets/*"],
47 | "@/config/*": ["config/*"],
48 | "@/store/*": ["store/*"],
49 | "@/utils/*": ["utils/*"],
50 | "vue": ["mpvue"]
51 | } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
52 | "rootDirs": [
53 | "./src"
54 | ] /* List of root folders whose combined content represents the structure of the project at runtime. */,
55 | "typeRoots": [
56 | "node_modules/@types",
57 | "types"
58 | ] /* List of folders to include type definitions from. */,
59 | // "types": [], /* Type declaration files to be included in compilation. */
60 | "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
61 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
62 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
63 |
64 | /* Source Map Options */
65 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
66 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
67 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
68 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
69 |
70 | /* Experimental Options */
71 | "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
72 | "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/_archive_ts/types/promise.d.ts:
--------------------------------------------------------------------------------
1 | interface Promise {
2 | finally: (onfinally?: (() => void) | null | undefined) => Promise;
3 | }
4 |
--------------------------------------------------------------------------------
/app/_archive_ts/types/shim.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.vue' {
2 | import Vue from 'vue';
3 | export default Vue;
4 | }
5 |
--------------------------------------------------------------------------------
/app/_archive_ts/types/vue.d.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import App from 'common-mpvue/types/app';
3 | import { VuexStore } from 'common-mpvue/types/internal';
4 | import { Store } from 'vuex/types';
5 |
6 | interface TabItem {
7 | index: number;
8 | pagePath: string;
9 | text: string;
10 | }
11 |
12 | declare module 'vue/types/options' {
13 | interface ComponentOptions {
14 | /**
15 | * 监听页面加载
16 | */
17 | onLoad?(): void;
18 |
19 | /**
20 | * 监听页面显示
21 | */
22 | onShow?(): void;
23 |
24 | /**
25 | * 监听页面初次渲染完成
26 | */
27 | onReady?(): void;
28 |
29 | /**
30 | * 监听页面隐藏
31 | */
32 | onHide?(): void;
33 |
34 | /**
35 | * 监听页面卸载
36 | */
37 | onUnload?(): void;
38 |
39 | /**
40 | * 监听用户下拉动作
41 | */
42 | onPullDownRefresh?(): void;
43 |
44 | /**
45 | * 页面上拉触底事件的处理函数
46 | */
47 | onReachBottom?(): void;
48 |
49 | /**
50 | *
51 | * @param res 用户点击右上角分享
52 | */
53 | onShareAppMessage?(res): any;
54 |
55 | /**
56 | * 页面滚动
57 | */
58 | onPageScroll?(e);
59 |
60 | /**
61 | * 当前是 tab 页时 // 点击 tab 时触发
62 | */
63 | onTabItemTap?(item);
64 |
65 | /**
66 | * Common-mpvue添加的入口App.vue独有的声明周期,在此声明周期内小程序app已经实例化完成,而其他onShow mounted声明周期内app未实例化完成
67 | */
68 | onLaunched();
69 | }
70 | }
71 |
72 | declare module 'vue/types/vue' {
73 | interface VueConstructor {
74 | mpType: string;
75 | }
76 |
77 | interface Vue {
78 | /**
79 | * 小程序app实例
80 | */
81 | $app: App;
82 |
83 | /**
84 | * 页面公用的业务Vuex Store
85 | */
86 | $store: Store;
87 | $_store: VuexStore;
88 |
89 | /**
90 | * 当前页面使用的Vuex模块State
91 | */
92 | $state: any;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/build/build.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const path = require('path');
3 | const { exec } = require('child_process');
4 | const ora = require('ora');
5 | const chalk = require('chalk');
6 |
7 | const appFolder = path.resolve(process.cwd(), 'app');
8 |
9 | // 删除archive压缩文件
10 | function removeFile(fileName) {
11 | return new Promise((resolve, reject) => {
12 | fs.unlink(path.resolve(appFolder, `${fileName}.zip`), function(error) {
13 | if (error) {
14 | reject(error);
15 | } else {
16 | resolve();
17 | }
18 | });
19 | });
20 | }
21 |
22 | // 压缩文件
23 | function zipFile(fileName) {
24 | return new Promise((resolve, reject) => {
25 | exec(`cd app && zip -q -r -o ${fileName}.zip ./${fileName}/`, function(
26 | error
27 | ) {
28 | if (error) {
29 | reject(error);
30 | } else {
31 | resolve();
32 | }
33 | });
34 | });
35 | }
36 |
37 | // git add 文件
38 | function gitAdd() {
39 | return new Promise((resolve, reject) => {
40 | exec('git add -A', function(error) {
41 | if (error) {
42 | reject(error);
43 | } else {
44 | resolve();
45 | }
46 | });
47 | });
48 | }
49 |
50 | const spinner = ora();
51 | spinner.start();
52 | spinner.text = chalk.white('Building...');
53 |
54 | (async function() {
55 | await Promise.all([removeFile('_archive'), removeFile('_archive_ts')])
56 | .then(() => Promise.all([zipFile('_archive'), zipFile('_archive_ts')]))
57 | .then(() => gitAdd())
58 | .then(() => {
59 | spinner.stop();
60 | console.log(chalk.green('Build successfully'));
61 | })
62 | .catch(error => {
63 | spinner.stop();
64 | console.log(chalk.red(`Build failed: ${error.message}`));
65 | });
66 | })();
67 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-mpvue-project",
3 | "version": "1.5.5",
4 | "description": "Yeoman generator of mpvue project",
5 | "main": "index.js",
6 | "repository": "git@github.com:thundernet8/generator-mpvue-project.git",
7 | "author": "wuxueqian ",
8 | "license": "MIT",
9 | "keywords": [
10 | "yeoman-generator",
11 | "mpvue",
12 | "wxapp",
13 | "webpack",
14 | "boilerplate"
15 | ],
16 | "files": [
17 | "app"
18 | ],
19 | "scripts": {
20 | "build": "node build/build.js",
21 | "prepublishOnly": "npm run build",
22 | "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
23 | "lint-staged": "lint-staged",
24 | "lint-staged:script": "eslint --fix -c .eslintrc",
25 | "lint-staged:format": "prettier --write",
26 | "lint": "eslint --ext .js app/index.js"
27 | },
28 | "pre-commit": [
29 | "precommit-msg",
30 | "lint-staged"
31 | ],
32 | "lint-staged": {
33 | "app/index.js": [
34 | "lint-staged:format",
35 | "lint-staged:script",
36 | "git add"
37 | ]
38 | },
39 | "dependencies": {
40 | "chalk": "^2.3.2",
41 | "get-installed-path": "^4.0.8",
42 | "mkdirp": "^0.5.1",
43 | "mv": "^2.1.1",
44 | "ora": "^2.0.0",
45 | "prettier": "^1.10.2",
46 | "prompt": "^1.0.0",
47 | "unzip": "^0.1.11",
48 | "update-check": "^1.3.1",
49 | "yeoman-generator": "^2.0.3"
50 | },
51 | "devDependencies": {
52 | "eslint": "^4.18.1",
53 | "eslint-config-airbnb-base": "^12.1.0",
54 | "eslint-plugin-import": "^2.9.0",
55 | "lint-staged": "^6.1.1",
56 | "pre-commit": "^1.2.2"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/screenshot/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/screenshot/screenshot1.png
--------------------------------------------------------------------------------
/screenshot/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/screenshot/screenshot2.png
--------------------------------------------------------------------------------
/screenshot/screenshot3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/screenshot/screenshot3.png
--------------------------------------------------------------------------------
/screenshot/screenshot4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/screenshot/screenshot4.png
--------------------------------------------------------------------------------
/screenshot/screenshot5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/screenshot/screenshot5.png
--------------------------------------------------------------------------------
/ts-example/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ts-example/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/ts-example/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/ts-example/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
5 | extends: ['standard', 'plugin:vue/essential'],
6 | // add your custom rules here
7 | rules: {
8 | // allow debugger during development
9 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
10 |
11 | 'wrap-iife': 0,
12 |
13 | 'space-before-function-paren': 0,
14 |
15 | semi: [2, 'always'],
16 |
17 | 'no-new': 0,
18 |
19 | 'vue/mustache-interpolation-spacing': 0,
20 | indent: [
21 | 0,
22 | 4,
23 | {
24 | SwitchCase: 1,
25 | VariableDeclarator: 1,
26 | outerIIFEBody: 1,
27 | FunctionDeclaration: {
28 | parameters: 1,
29 | body: 1
30 | },
31 | FunctionExpression: {
32 | parameters: 1,
33 | body: 1
34 | }
35 | }
36 | ]
37 | },
38 | globals: {
39 | App: true,
40 | Page: true,
41 | wx: true,
42 | getApp: true,
43 | getPage: true,
44 | getCurrentPages: true
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/ts-example/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | .vscode/
61 | .dll/
62 | dist/
--------------------------------------------------------------------------------
/ts-example/.lintstagedrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | 'src/**/*.{ts,tsx}': ['lint-staged:format', 'lint-staged:ts', 'git add'],
3 | 'src/**/*.{js,vue}': ['lint-staged:format', 'lint-staged:js', 'git add']
4 | };
5 |
--------------------------------------------------------------------------------
/ts-example/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {},
7 | "postcss-mpvue-wxss": {}
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ts-example/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/ts-example/.tslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["tslint-eslint-rules"],
3 | "rules": {
4 | "align": [true, "parameters", "statements"],
5 | "class-name": true,
6 | "comment-format": [true, "check-space"],
7 | "curly": true,
8 | "object-curly-spacing": true,
9 | "eofline": true,
10 | "forin": true,
11 | "indent": [true, "spaces"],
12 | "jsdoc-format": false,
13 | "label-position": true,
14 | "max-line-length": [false, 120],
15 | "member-ordering": [
16 | false,
17 | {
18 | "order": "statics-first"
19 | }
20 | ],
21 | "new-parens": true,
22 | "no-any": false,
23 | "no-arg": true,
24 | "no-bitwise": true,
25 | "no-conditional-assignment": true,
26 | "no-consecutive-blank-lines": true,
27 | "no-console": [
28 | true,
29 | "debug",
30 | "info",
31 | "log",
32 | "time",
33 | "timeEnd",
34 | "trace"
35 | ],
36 | "no-construct": true,
37 | "no-constructor-vars": false,
38 | "no-debugger": true,
39 | "no-duplicate-variable": true,
40 | "no-empty": false,
41 | "no-eval": true,
42 | "no-internal-module": true,
43 | "no-namespace": true,
44 | "no-reference": true,
45 | "no-shadowed-variable": true,
46 | "no-string-literal": true,
47 | "no-switch-case-fall-through": false,
48 | "no-trailing-whitespace": true,
49 | "no-unused-expression": true,
50 | "no-use-before-declare": false,
51 | "no-var-keyword": true,
52 | "no-var-requires": false,
53 | "object-literal-sort-keys": false,
54 | "one-line": [
55 | true,
56 | "check-catch",
57 | "check-else",
58 | "check-finally",
59 | "check-open-brace",
60 | "check-whitespace"
61 | ],
62 | "one-variable-per-declaration": [true, "ignore-for-loop"],
63 | "quotemark": [true, "double", "jsx-double"],
64 | "radix": true,
65 | "semicolon": [true, "always", "ignore-bound-class-methods"],
66 | "switch-default": true,
67 | "trailing-comma": [
68 | true,
69 | {
70 | "singleline": "never",
71 | "multiline": "never"
72 | }
73 | ],
74 | "triple-equals": [true, "allow-null-check"],
75 | "typedef": false,
76 | "typedef-whitespace": [
77 | true,
78 | {
79 | "call-signature": "nospace",
80 | "index-signature": "nospace",
81 | "parameter": "nospace",
82 | "property-declaration": "nospace",
83 | "variable-declaration": "nospace"
84 | },
85 | {
86 | "call-signature": "onespace",
87 | "index-signature": "onespace",
88 | "parameter": "onespace",
89 | "property-declaration": "onespace",
90 | "variable-declaration": "onespace"
91 | }
92 | ],
93 | "use-isnan": true,
94 | "variable-name": [
95 | true,
96 | "allow-leading-underscore",
97 | "ban-keywords",
98 | "check-format",
99 | "allow-pascal-case"
100 | ],
101 | "whitespace": [
102 | true,
103 | "check-branch",
104 | "check-decl",
105 | "check-operator",
106 | "check-separator",
107 | "check-type",
108 | "check-typecast"
109 | ]
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/ts-example/README.md:
--------------------------------------------------------------------------------
1 | ## 使用
2 |
3 | 开发
4 |
5 | ```js
6 | npm run dev
7 | ```
8 |
9 | 开发并本地 mock API
10 |
11 | ```js
12 | npm run dev:mock
13 | ```
14 |
15 | 生产打包
16 |
17 | ```js
18 | npm run build
19 | ```
20 |
21 | ## common-mpvue
22 |
23 | [common-mpvue](https://github.com/thundernet8/common-mpvue)
24 |
--------------------------------------------------------------------------------
/ts-example/build/build.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')();
2 |
3 | process.env.NODE_ENV = 'production';
4 |
5 | var ora = require('ora');
6 | var rm = require('rimraf');
7 | var path = require('path');
8 | var chalk = require('chalk');
9 | var webpack = require('webpack');
10 | var config = require('../config');
11 | var webpackConfig = require('./webpack.prod.conf');
12 |
13 | var spinner = ora('building for production...');
14 | spinner.start();
15 |
16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
17 | if (err) throw err;
18 | webpack(webpackConfig, function(err, stats) {
19 | spinner.stop();
20 | if (err) throw err;
21 | process.stdout.write(
22 | stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false,
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n'
29 | );
30 |
31 | if (stats.hasErrors()) {
32 | console.log(chalk.red(' Build failed with errors.\n'));
33 | process.exit(1);
34 | }
35 |
36 | console.log(chalk.cyan(' Build complete.\n'));
37 | console.log(
38 | chalk.yellow(
39 | ' Tip: built files are meant to be served over an HTTP server.\n' +
40 | " Opening index.html over file:// won't work.\n"
41 | )
42 | );
43 | });
44 | });
45 |
--------------------------------------------------------------------------------
/ts-example/build/check-versions.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk');
2 | var semver = require('semver');
3 | var packageConfig = require('../package.json');
4 | var shell = require('shelljs');
5 | function exec(cmd) {
6 | return require('child_process')
7 | .execSync(cmd)
8 | .toString()
9 | .trim();
10 | }
11 |
12 | var versionRequirements = [
13 | {
14 | name: 'node',
15 | currentVersion: semver.clean(process.version),
16 | versionRequirement: packageConfig.engines.node
17 | }
18 | ];
19 |
20 | if (shell.which('npm')) {
21 | versionRequirements.push({
22 | name: 'npm',
23 | currentVersion: exec('npm --version'),
24 | versionRequirement: packageConfig.engines.npm
25 | });
26 | }
27 |
28 | module.exports = function() {
29 | var warnings = [];
30 | for (var i = 0; i < versionRequirements.length; i++) {
31 | var mod = versionRequirements[i];
32 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
33 | warnings.push(
34 | mod.name +
35 | ': ' +
36 | chalk.red(mod.currentVersion) +
37 | ' should be ' +
38 | chalk.green(mod.versionRequirement)
39 | );
40 | }
41 | }
42 |
43 | if (warnings.length) {
44 | console.log('');
45 | console.log(
46 | chalk.yellow(
47 | 'To use this template, you must update following to modules:'
48 | )
49 | );
50 | console.log();
51 | for (var i = 0; i < warnings.length; i++) {
52 | var warning = warnings[i];
53 | console.log(' ' + warning);
54 | }
55 | console.log();
56 | process.exit(1);
57 | }
58 | };
59 |
--------------------------------------------------------------------------------
/ts-example/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 |
--------------------------------------------------------------------------------
/ts-example/build/dev-server.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')();
2 |
3 | var config = require('../config');
4 | if (!process.env.NODE_ENV) {
5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV);
6 | }
7 |
8 | // var opn = require('opn')
9 | var path = require('path');
10 | var express = require('express');
11 | var webpack = require('webpack');
12 | var proxyMiddleware = require('http-proxy-middleware');
13 | var webpackConfig = require('./webpack.dev.conf');
14 |
15 | // default port where dev server listens for incoming traffic
16 | var port = process.env.PORT || config.dev.port;
17 | // automatically open browser, if not set will be false
18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser;
19 | // Define HTTP proxies to your custom API backend
20 | // https://github.com/chimurai/http-proxy-middleware
21 | var proxyTable = config.dev.proxyTable;
22 |
23 | var chokidar = require('chokidar');
24 |
25 | var DynamicEntryPlugin = require('webpack/lib/DynamicEntryPlugin');
26 |
27 | var mock = require('./mock');
28 |
29 | var app = express();
30 |
31 | // 检验dll-dev.js是否编译,否则尝试编译
32 | function dll() {
33 | const dllPath = path.resolve(webpackConfig.output.path, 'dll-dev.js');
34 | if (fs.existsSync(dllPath)) {
35 | const stats = fs.statSync(dllPath);
36 | const now = new Date();
37 | const modifyTime = new Date(stats.mtime);
38 | if (now - modifyTime < 600 * 1000) {
39 | // 10min内新鲜的dll-dev.js不再更新
40 | return Promise.resolve(true);
41 | }
42 | }
43 | // 超过10min未更新或不存在重新编译
44 | return new Promise((resolve, reject) => {
45 | webpack(dllWebpackConfig, (err, stats) => {
46 | if (err) {
47 | reject(err);
48 | } else {
49 | process.stdout.write(
50 | stats.toString({
51 | colors: true,
52 | modules: false,
53 | children: false,
54 | chunks: false,
55 | chunkModules: false
56 | }) + '\n\n'
57 | );
58 | resolve(true);
59 | }
60 | });
61 | });
62 | }
63 |
64 | function dev() {
65 | var compiler = webpack(webpackConfig);
66 |
67 | // var devMiddleware = require('webpack-dev-middleware')(compiler, {
68 | // publicPath: webpackConfig.output.publicPath,
69 | // quiet: true
70 | // })
71 |
72 | // var hotMiddleware = require('webpack-hot-middleware')(compiler, {
73 | // log: false,
74 | // heartbeat: 2000
75 | // })
76 | // force page reload when html-webpack-plugin template changes
77 | // compiler.plugin('compilation', function (compilation) {
78 | // compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
79 | // hotMiddleware.publish({ action: 'reload' })
80 | // cb()
81 | // })
82 | // })
83 |
84 | // proxy api requests
85 | Object.keys(proxyTable).forEach(function(context) {
86 | var options = proxyTable[context];
87 | if (typeof options === 'string') {
88 | options = { target: options };
89 | }
90 | app.use(proxyMiddleware(options.filter || context, options));
91 | });
92 |
93 | // simple json mock
94 | app.all('/mocks/*', mock);
95 |
96 | // handle fallback for HTML5 history API
97 | app.use(require('connect-history-api-fallback')());
98 |
99 | // serve webpack bundle output
100 | // app.use(devMiddleware)
101 |
102 | // enable hot-reload and state-preserving
103 | // compilation error display
104 | // app.use(hotMiddleware)
105 |
106 | // serve pure static assets
107 | var staticPath = path.posix.join(
108 | config.dev.assetsPublicPath,
109 | config.dev.assetsSubDirectory
110 | );
111 | app.use(staticPath, express.static('./static'));
112 |
113 | var uri = 'http://localhost:' + port;
114 |
115 | var _resolve;
116 | var readyPromise = new Promise(resolve => {
117 | _resolve = resolve;
118 | });
119 |
120 | // console.log('> Starting dev server...')
121 | // devMiddleware.waitUntilValid(() => {
122 | // console.log('> Listening at ' + uri + '\n')
123 | // // when env is testing, don't need open it
124 | // if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
125 | // opn(uri)
126 | // }
127 | // _resolve()
128 | // })
129 |
130 | var server = app.listen(port, 'localhost');
131 |
132 | // for 小程序的文件保存机制
133 | require('webpack-dev-middleware-hard-disk')(compiler, {
134 | publicPath: webpackConfig.output.publicPath,
135 | quiet: true
136 | });
137 |
138 | compiler.run((err, stats) => {
139 | // console.log('callback')
140 | const entries = Object.keys(webpackConfig.entry);
141 | console.log(entries);
142 | chokidar.watch(process.cwd() + '/src/pages').on('add', path => {
143 | // console.log(`File ${path} has been added`);
144 | if (path.endsWith('/main.ts')) {
145 | const reg = new RegExp(
146 | `${process.cwd()}/src/pages/(.+)/main.ts`,
147 | 'i'
148 | );
149 | const match = path.match(reg);
150 | if (match && !entries.includes(match[1])) {
151 | console.log(match[1]);
152 | const dep = DynamicEntryPlugin.createDependency(
153 | path,
154 | match[1]
155 | );
156 | compilation.addEntry(context, dep, match[1], err => {
157 | if (err) {
158 | return reject(err);
159 | } else {
160 | return resolve();
161 | }
162 | });
163 |
164 | compiler.watch({}).invalidate();
165 | }
166 | }
167 | });
168 | });
169 |
170 | return readyPromise;
171 | }
172 |
173 | var readyPromise = dll().then(() => dev());
174 |
175 | module.exports = {
176 | ready: readyPromise,
177 | close: () => {
178 | server.close();
179 | }
180 | };
181 |
--------------------------------------------------------------------------------
/ts-example/build/mock.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const fs = require('fs');
3 |
4 | module.exports = function mock(req, res) {
5 | const reqPath = req.path.slice(1);
6 | const jsonPath = path.resolve(__dirname, '../src', `${reqPath}.json`);
7 | console.log(`[** mocks **]: use ${jsonPath}`);
8 | try {
9 | // TODO require有缓存,在运行过程中修改json不会生效,需要重启dev server
10 | // TODO fs.readFileSync
11 | // const json = require(jsonPath);
12 | const json = fs.readFileSync(jsonPath).toString();
13 | res.json(JSON.parse(json));
14 | } catch (e) {
15 | if (e.message && e.message.indexOf('no such file or directory') > -1) {
16 | console.log('Mock json file not found');
17 | // res.json(JSON.stringify({}));
18 | res.status(404).end(`Mock json file not found: ${jsonPath}`);
19 | return;
20 | }
21 | throw e;
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/ts-example/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 =
7 | process.env.NODE_ENV === 'production'
8 | ? config.build.assetsSubDirectory
9 | : config.dev.assetsSubDirectory;
10 | return path.posix.join(assetsSubDirectory, _path);
11 | };
12 |
13 | exports.cssLoaders = function(options) {
14 | options = options || {};
15 |
16 | var cssLoader = {
17 | loader: 'css-loader',
18 | options: {
19 | minimize: process.env.NODE_ENV === 'production',
20 | sourceMap: options.sourceMap
21 | }
22 | };
23 |
24 | var postcssLoader = {
25 | loader: 'postcss-loader',
26 | options: {
27 | sourceMap: true
28 | }
29 | };
30 |
31 | var px2rpxLoader = {
32 | loader: 'px2rpx-loader',
33 | options: {
34 | baseDpr: 1,
35 | rpxUnit: 0.5
36 | }
37 | };
38 |
39 | // generate loader string to be used with extract text plugin
40 | function generateLoaders(loader, loaderOptions) {
41 | var loaders = [cssLoader, postcssLoader, px2rpxLoader];
42 | if (loader) {
43 | loaders.push({
44 | loader: loader + '-loader',
45 | options: Object.assign({}, loaderOptions, {
46 | sourceMap: options.sourceMap
47 | })
48 | });
49 | }
50 |
51 | // Extract CSS when that option is specified
52 | // (which is the case during production build)
53 | if (options.extract) {
54 | return ExtractTextPlugin.extract({
55 | use: loaders,
56 | fallback: 'vue-style-loader'
57 | });
58 | } else {
59 | return ['vue-style-loader'].concat(loaders);
60 | }
61 | }
62 |
63 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
64 | return {
65 | css: generateLoaders(),
66 | postcss: generateLoaders(),
67 | less: generateLoaders('less'),
68 | sass: generateLoaders('sass', { indentedSyntax: true }),
69 | scss: generateLoaders('sass'),
70 | stylus: generateLoaders('stylus'),
71 | styl: generateLoaders('stylus')
72 | };
73 | };
74 |
75 | // Generate loaders for standalone style files (outside of .vue)
76 | exports.styleLoaders = function(options) {
77 | var output = [];
78 | var loaders = exports.cssLoaders(options);
79 | for (var extension in loaders) {
80 | var loader = loaders[extension];
81 | output.push({
82 | test: new RegExp('\\.' + extension + '$'),
83 | use: loader
84 | });
85 | }
86 | return output;
87 | };
88 |
--------------------------------------------------------------------------------
/ts-example/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var config = require('../config');
3 | // var isProduction = process.env.NODE_ENV === 'production'
4 | // for mp
5 | var isProduction = true;
6 |
7 | module.exports = {
8 | loaders: utils.cssLoaders({
9 | sourceMap: isProduction
10 | ? config.build.productionSourceMap
11 | : config.dev.cssSourceMap,
12 | extract: isProduction
13 | }),
14 | transformToRequire: {
15 | video: 'src',
16 | source: 'src',
17 | img: 'src',
18 | image: 'xlink:href'
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/ts-example/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils');
2 | var webpack = require('webpack');
3 | var config = require('../config');
4 | var merge = require('webpack-merge');
5 | var baseWebpackConfig = require('./webpack.base.conf');
6 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
8 |
9 | // copy from ./webpack.prod.conf.js
10 | var path = require('path');
11 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
12 | var CopyWebpackPlugin = require('copy-webpack-plugin');
13 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
14 |
15 | // add hot-reload related code to entry chunks
16 | // Object.keys(baseWebpackConfig.entry).forEach(function (name) {
17 | // baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
18 | // })
19 |
20 | module.exports = merge(baseWebpackConfig, {
21 | module: {
22 | rules: utils.styleLoaders({
23 | sourceMap: config.dev.cssSourceMap,
24 | extract: true
25 | })
26 | },
27 | // cheap-module-eval-source-map is faster for development
28 | // devtool: '#cheap-module-eval-source-map',
29 | devtool: '#source-map',
30 | output: {
31 | path: config.build.assetsRoot,
32 | // filename: utils.assetsPath('js/[name].[chunkhash].js'),
33 | // chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
34 | filename: utils.assetsPath('js/[name].js'),
35 | chunkFilename: utils.assetsPath('js/[id].js')
36 | },
37 | plugins: [
38 | new webpack.DefinePlugin({
39 | 'process.env': config.dev.env
40 | }),
41 |
42 | // copy from ./webpack.prod.conf.js
43 | // extract css into its own file
44 | new ExtractTextPlugin({
45 | // filename: utils.assetsPath('css/[name].[contenthash].css')
46 | filename: utils.assetsPath('css/[name].wxss')
47 | }),
48 | // Compress extracted CSS. We are using this plugin so that possible
49 | // duplicated CSS from different components can be deduped.
50 | new OptimizeCSSPlugin({
51 | cssProcessorOptions: {
52 | safe: true
53 | }
54 | }),
55 | new webpack.optimize.CommonsChunkPlugin({
56 | name: 'vendor',
57 | minChunks: function(module, count) {
58 | // any required modules inside node_modules are extracted to vendor
59 | return (
60 | module.resource &&
61 | /\.js$/.test(module.resource) &&
62 | module.resource.indexOf('node_modules') >= 0
63 | );
64 | }
65 | }),
66 | new webpack.optimize.CommonsChunkPlugin({
67 | name: 'manifest',
68 | chunks: ['vendor']
69 | }),
70 | // copy custom static assets
71 | new CopyWebpackPlugin([
72 | {
73 | from: path.resolve(__dirname, '../static'),
74 | to: config.build.assetsSubDirectory,
75 | ignore: ['.*']
76 | }
77 | ]),
78 |
79 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
80 | // new webpack.HotModuleReplacementPlugin(),
81 | new webpack.NoEmitOnErrorsPlugin(),
82 | // https://github.com/ampedandwired/html-webpack-plugin
83 | // new HtmlWebpackPlugin({
84 | // filename: 'index.html',
85 | // template: 'index.html',
86 | // inject: true
87 | // }),
88 | new FriendlyErrorsPlugin()
89 | ]
90 | });
91 |
--------------------------------------------------------------------------------
/ts-example/build/webpack.dll.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var config = require('../config');
3 | var webpack = require('webpack');
4 |
5 | function resolve(dir) {
6 | return path.join(__dirname, '..', dir);
7 | }
8 |
9 | const plugins = [];
10 | if (config.build.bundleAnalyzerReport) {
11 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
12 | .BundleAnalyzerPlugin;
13 | plugins.push(new BundleAnalyzerPlugin());
14 | }
15 |
16 | module.exports = {
17 | entry: {
18 | dll: [
19 | 'mpvue',
20 | 'vuex',
21 | 'common-mpvue',
22 | 'querystring',
23 | 'url-parse',
24 | 'md5',
25 | 'left-pad',
26 | 'date-fns'
27 | ]
28 | },
29 | output: {
30 | path: path.resolve(__dirname, '../dist'), //config.build.assetsRoot,
31 | filename:
32 | process.env.NODE_ENV === 'production' ? 'dll.js' : 'dll-dev.js',
33 | publicPath:
34 | process.env.NODE_ENV === 'production'
35 | ? config.build.assetsPublicPath
36 | : config.dev.assetsPublicPath,
37 | library: 'dll',
38 | libraryTarget: 'commonjs2'
39 | },
40 | resolve: {
41 | extensions: ['.js', '.json'],
42 | alias: {
43 | vue: 'mpvue',
44 | '@': resolve('src')
45 | },
46 | symlinks: false
47 | },
48 | module: {
49 | rules: [
50 | {
51 | test: /\.js$/,
52 | include: [resolve('src'), resolve('test')],
53 | use: ['babel-loader']
54 | }
55 | ]
56 | },
57 | plugins: [
58 | ...plugins,
59 | new webpack.DllPlugin({
60 | context: __dirname,
61 | path: '.dll/manifest.json',
62 | name: '[name]'
63 | }),
64 | new webpack.HashedModuleIdsPlugin()
65 | // new webpack.optimize.UglifyJsPlugin({
66 | // compress: {
67 | // warnings: false
68 | // },
69 | // sourceMap: false
70 | // })
71 | ]
72 | };
73 |
--------------------------------------------------------------------------------
/ts-example/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var utils = require('./utils');
3 | var webpack = require('webpack');
4 | var config = require('../config');
5 | var merge = require('webpack-merge');
6 | var baseWebpackConfig = require('./webpack.base.conf');
7 | var CopyWebpackPlugin = require('copy-webpack-plugin');
8 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
9 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
11 | var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
12 |
13 | var env = config.build.env;
14 |
15 | var webpackConfig = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({
18 | sourceMap: config.build.productionSourceMap,
19 | extract: true
20 | })
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 | filename: utils.assetsPath('js/[name].js'),
28 | chunkFilename: utils.assetsPath('js/[id].js')
29 | },
30 | plugins: [
31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
32 | new webpack.DefinePlugin({
33 | 'process.env': env
34 | }),
35 | new UglifyJsPlugin({
36 | sourceMap: true
37 | }),
38 | // extract css into its own file
39 | new ExtractTextPlugin({
40 | // filename: utils.assetsPath('css/[name].[contenthash].css')
41 | filename: utils.assetsPath('css/[name].wxss')
42 | }),
43 | // Compress extracted CSS. We are using this plugin so that possible
44 | // duplicated CSS from different components can be deduped.
45 | new OptimizeCSSPlugin({
46 | cssProcessorOptions: {
47 | safe: true
48 | }
49 | }),
50 | // generate dist index.html with correct asset hash for caching.
51 | // you can customize output by editing /index.html
52 | // see https://github.com/ampedandwired/html-webpack-plugin
53 | // new HtmlWebpackPlugin({
54 | // filename: config.build.index,
55 | // template: 'index.html',
56 | // inject: true,
57 | // minify: {
58 | // removeComments: true,
59 | // collapseWhitespace: true,
60 | // removeAttributeQuotes: true
61 | // // more options:
62 | // // https://github.com/kangax/html-minifier#options-quick-reference
63 | // },
64 | // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
65 | // chunksSortMode: 'dependency'
66 | // }),
67 | // keep module.id stable when vender modules does not change
68 | new webpack.HashedModuleIdsPlugin(),
69 | // split vendor js into its own file
70 | new webpack.optimize.CommonsChunkPlugin({
71 | name: 'vendor',
72 | minChunks: function(module, count) {
73 | // any required modules inside node_modules are extracted to vendor
74 | return (
75 | module.resource &&
76 | /\.js$/.test(module.resource) &&
77 | module.resource.indexOf('node_modules') >= 0
78 | );
79 | }
80 | }),
81 | // extract webpack runtime and module manifest to its own file in order to
82 | // prevent vendor hash from being updated whenever app bundle is updated
83 | new webpack.optimize.CommonsChunkPlugin({
84 | name: 'manifest',
85 | chunks: ['vendor']
86 | }),
87 | // copy custom static assets
88 | new CopyWebpackPlugin([
89 | {
90 | from: path.resolve(__dirname, '../static'),
91 | to: config.build.assetsSubDirectory,
92 | ignore: ['.*']
93 | }
94 | ])
95 | ]
96 | });
97 |
98 | // if (config.build.productionGzip) {
99 | // var CompressionWebpackPlugin = require('compression-webpack-plugin')
100 |
101 | // webpackConfig.plugins.push(
102 | // new CompressionWebpackPlugin({
103 | // asset: '[path].gz[query]',
104 | // algorithm: 'gzip',
105 | // test: new RegExp(
106 | // '\\.(' +
107 | // config.build.productionGzipExtensions.join('|') +
108 | // ')$'
109 | // ),
110 | // threshold: 10240,
111 | // minRatio: 0.8
112 | // })
113 | // )
114 | // }
115 |
116 | if (config.build.bundleAnalyzerReport) {
117 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
118 | .BundleAnalyzerPlugin;
119 | webpackConfig.plugins.push(new BundleAnalyzerPlugin());
120 | }
121 |
122 | module.exports = webpackConfig;
123 |
--------------------------------------------------------------------------------
/ts-example/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 | PORT: 8080,
7 | MOCK: process.env.MOCK,
8 | PKG_TYPE: process.env.PKG_TYPE
9 | });
10 |
--------------------------------------------------------------------------------
/ts-example/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path');
3 | var env = require('./dev.env');
4 |
5 | module.exports = {
6 | build: {
7 | env: require('./prod.env'),
8 | index: path.resolve(__dirname, '../dist/index.html'),
9 | assetsRoot: path.resolve(__dirname, '../dist'),
10 | assetsSubDirectory: 'static',
11 | assetsPublicPath: '/',
12 | productionSourceMap: false,
13 | // Gzip off by default as many popular static hosts such as
14 | // Surge or Netlify already gzip all static assets for you.
15 | // Before setting to `true`, make sure to:
16 | // npm install --save-dev compression-webpack-plugin
17 | productionGzip: false,
18 | productionGzipExtensions: ['js', 'css'],
19 | // Run the build command with an extra argument to
20 | // View the bundle analyzer report after build finishes:
21 | // `npm run build --report`
22 | // Set to `true` or `false` to always turn it on or off
23 | bundleAnalyzerReport: process.env.npm_config_report
24 | },
25 | dev: {
26 | env,
27 | port: env.PORT,
28 | // 在小程序开发者工具中不需要自动打开浏览器
29 | autoOpenBrowser: false,
30 | assetsSubDirectory: 'static',
31 | assetsPublicPath: '/',
32 | proxyTable: {},
33 | // CSS Sourcemaps off by default because relative paths are "buggy"
34 | // with this option, according to the CSS-Loader README
35 | // (https://github.com/webpack/css-loader#sourcemaps)
36 | // In our experience, they generally work as expected,
37 | // just be aware of this issue when enabling this option.
38 | cssSourceMap: false
39 | }
40 | };
41 |
--------------------------------------------------------------------------------
/ts-example/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | };
4 |
--------------------------------------------------------------------------------
/ts-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ts-example",
3 | "version": "1.0.0",
4 | "description": "由generator-mpvue-project脚手架生成的TypeScript版本示例",
5 | "private": true,
6 | "scripts": {
7 | "lint-staged": "lint-staged -c .lintstagedrc.js",
8 | "lint": "npm run lint:js && npm run lint:ts",
9 | "lint:js": "eslint --fix --ext .js,.vue src",
10 | "lint:ts": "tslint -e node_modules --fix -c .tslintrc.json src/**/*.ts",
11 | "lint-staged:js": "eslint --fix -c .eslintrc.js",
12 | "lint-staged:ts": "tslint --fix -c .tslintrc.json",
13 | "lint-staged:format": "prettier --write",
14 | "format":
15 | "prettier --write --tab-width 4 --single-quote true --stdin-filepath src/**/*.{less,vue,js}",
16 | "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
17 | "dll":
18 | "cross-env NODE_ENV=production webpack -p --hide-modules --config build/webpack.dll.conf.js",
19 | "dll:dev":
20 | "cross-env NODE_ENV=development webpack --hide-modules --config build/webpack.dll.conf.js",
21 | "dll:report":
22 | "cross-env npm_config_report=true NODE_ENV=production webpack --hide-modules --config build/webpack.dll.conf.js",
23 | "dev": "node build/dev-server.js",
24 | "dev:mock": "cross-env MOCK=true node build/dev-server.js",
25 | "start": "npm run dll:dev && node build/dev-server.js",
26 | "build": " rimraf dist && npm run dll && node build/build.js",
27 | "build:report":
28 | "rimraf dist && npm run dll && cross-env npm_config_report=true node build/build.js"
29 | },
30 | "dependencies": {
31 | "@types/node": "^9.6.2",
32 | "common-mpvue": "latest",
33 | "date-fns": "^1.29.0",
34 | "left-pad": "^1.2.0",
35 | "md5": "^2.2.1",
36 | "mpvue": "^1.0.9",
37 | "querystring": "^0.2.0",
38 | "url-parse": "^1.2.0",
39 | "vue-property-decorator": "^6.0.0",
40 | "vuex": "^3.0.1"
41 | },
42 | "devDependencies": {
43 | "autoprefixer": "^7.1.2",
44 | "babel-core": "^6.22.1",
45 | "babel-eslint": "^7.1.1",
46 | "babel-loader": "^7.1.1",
47 | "babel-plugin-transform-runtime": "^6.22.0",
48 | "babel-preset-env": "^1.3.2",
49 | "babel-preset-stage-2": "^6.22.0",
50 | "babel-register": "^6.22.0",
51 | "chalk": "^2.0.1",
52 | "chokidar": "^2.0.2",
53 | "connect-history-api-fallback": "^1.3.0",
54 | "copy-webpack-plugin": "^4.5.1",
55 | "cross-env": "^5.1.4",
56 | "css-loader": "^0.28.0",
57 | "cssnano": "^3.10.0",
58 | "eslint": "^4.19.1",
59 | "eslint-config-standard": "^11.0.0",
60 | "eslint-friendly-formatter": "^3.0.0",
61 | "eslint-loader": "^1.7.1",
62 | "eslint-plugin-html": "^3.0.0",
63 | "eslint-plugin-import": "^2.10.0",
64 | "eslint-plugin-node": "^6.0.1",
65 | "eslint-plugin-promise": "^3.4.0",
66 | "eslint-plugin-standard": "^2.0.1",
67 | "eslint-plugin-vue": "^4.4.0",
68 | "eventsource-polyfill": "^0.9.6",
69 | "express": "^4.14.1",
70 | "extract-text-webpack-plugin": "^2.0.0",
71 | "file-loader": "^0.11.1",
72 | "friendly-errors-webpack-plugin": "^1.1.3",
73 | "html-webpack-plugin": "^2.28.0",
74 | "http-proxy-middleware": "^0.17.3",
75 | "koa": "^2.5.0",
76 | "less": "^3.0.1",
77 | "less-loader": "^4.1.0",
78 | "lint-staged": "^6.1.1",
79 | "mpvue-loader": "^1.0.10",
80 | "mpvue-template-compiler": "^1.0.9",
81 | "mpvue-ts-loader": "^1.0.5",
82 | "mpvue-webpack-target": "^1.0.0",
83 | "opn": "^5.1.0",
84 | "optimize-css-assets-webpack-plugin": "^2.0.0",
85 | "ora": "^1.2.0",
86 | "postcss-loader": "^2.0.6",
87 | "postcss-mpvue-wxss": "^1.0.0",
88 | "pre-commit": "^1.2.2",
89 | "prettier": "^1.11.1",
90 | "px2rpx-loader": "^0.1.8",
91 | "rimraf": "^2.6.2",
92 | "semver": "^5.3.0",
93 | "shelljs": "^0.7.6",
94 | "string-replace-webpack-plugin": "^0.1.3",
95 | "stylelint": "^9.1.3",
96 | "ts-loader": "^3.5.0",
97 | "tslint": "^5.9.1",
98 | "tslint-eslint-rules": "^5.1.0",
99 | "typescript": "^2.8.1",
100 | "uglifyjs-webpack-plugin": "^1.2.4",
101 | "url-loader": "^0.5.8",
102 | "vue": "^2.5.16",
103 | "vue-style-loader": "^3.0.1",
104 | "webpack": "^2.6.1",
105 | "webpack-bundle-analyzer": "^2.2.1",
106 | "webpack-dev-middleware": "^1.10.0",
107 | "webpack-dev-middleware-hard-disk": "^1.10.0",
108 | "webpack-hot-middleware": "^2.18.0",
109 | "webpack-merge": "^4.1.0"
110 | },
111 | "engines": { "node": ">= 4.0.0", "npm": ">= 3.0.0" },
112 | "browserslist": ["> 1%", "last 2 versions", "not ie <= 8"],
113 | "pre-commit": ["precommit-msg", "lint-staged"],
114 | "main": "index.js",
115 | "author": "wuxueqian ",
116 | "license": "MIT",
117 | "ts": "Y",
118 | "yarn": "Y",
119 | "appid": ""
120 | }
121 |
--------------------------------------------------------------------------------
/ts-example/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": false,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "compileType": "miniprogram",
11 | "libVersion": "1.9.93",
12 | "appid": "",
13 | "projectname": "ts-example",
14 | "isGameTourist": false,
15 | "condition": {
16 | "search": { "current": -1, "list": [] },
17 | "conversation": { "current": -1, "list": [] },
18 | "game": { "currentL": -1, "list": [] },
19 | "miniprogram": { "current": -1, "list": [] }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ts-example/src/App.vue:
--------------------------------------------------------------------------------
1 |
29 |
30 |
33 |
--------------------------------------------------------------------------------
/ts-example/src/api/home.ts:
--------------------------------------------------------------------------------
1 | import { wx } from 'common-mpvue';
2 |
3 | const httpRequest = wx.httpRequest
4 | .auth()
5 | .tokenKey('token')
6 | .qsToken();
7 |
8 | // 示例请求
9 | export function exampleRequest() {
10 | return httpRequest.GET('/examples');
11 | }
12 |
--------------------------------------------------------------------------------
/ts-example/src/assets/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/src/assets/images/loading.gif
--------------------------------------------------------------------------------
/ts-example/src/assets/styles/global.less:
--------------------------------------------------------------------------------
1 | .container {
2 | font-family: 'Microsoft YaHei', Helvetica, STHeiTi, sans-seri;
3 | position: relative;
4 | background-color: #e7e7e7;
5 | display: flex;
6 | flex-direction: column;
7 | min-height: 100vh;
8 | & > .section {
9 | flex-shrink: 0;
10 | flex-grow: 0;
11 | }
12 | .placeholder-container {
13 | flex: 1;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ts-example/src/common/app.ts:
--------------------------------------------------------------------------------
1 | // 扩展app实例的方法和属性
2 | export default {
3 | genName() {
4 | return this.name;
5 | }
6 | };
7 |
--------------------------------------------------------------------------------
/ts-example/src/components/board.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{title}}
4 |
{{content}}
5 |
6 |
7 |
8 |
25 |
26 |
42 |
--------------------------------------------------------------------------------
/ts-example/src/config/index.ts:
--------------------------------------------------------------------------------
1 | const DOMAIN_MAP = {
2 | development: process.env.MOCK
3 | ? `http://localhost:${process.env.PORT}/mocks`
4 | : 'http://beta.example.com',
5 | beta: 'http://beta.example.com',
6 | production: 'https://api.example.com'
7 | };
8 |
9 | export default {
10 | VERSION: '1.0.0',
11 | APP_NAME: 'sample-mpvue-wxapp',
12 | MOCK: process.env.MOCK && process.env.MOCK.toString() === 'true',
13 | DEBUG: process.env.NODE_ENV !== 'production',
14 | DOMAIN:
15 | DOMAIN_MAP[process.env.NODE_ENV || 'production'] ||
16 | 'https://api.example.com'
17 | };
18 |
--------------------------------------------------------------------------------
/ts-example/src/main.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import { Component } from 'vue-property-decorator';
3 | import App from './App.vue';
4 | import { wrap, wx } from 'common-mpvue';
5 | import config from './config';
6 | import appProps from './common/app';
7 |
8 | const pkg = require('../package.json');
9 |
10 | // 设置wx debug模式
11 | if (process.env.NODE_ENV !== 'production') {
12 | wx.setEnableDebug({ enableDebug: true });
13 | }
14 |
15 | Vue.config.productionTip = false;
16 | // 添加小程序hooks http://mpvue.com/mpvue/#_4
17 | Component.registerHooks([
18 | // pages
19 | 'onLoad', // 监听页面加载
20 | 'onShow', // 监听页面显示
21 | 'onReady', // 监听页面初次渲染完成
22 | 'onHide', // 监听页面隐藏
23 | 'onUnload', // 监听页面卸载
24 | 'onPullDownRefresh', // 监听用户下拉动作
25 | 'onReachBottom', // 页面上拉触底事件的处理函数
26 | 'onShareAppMessage', // 用户点击右上角分享
27 | 'onPageScroll', // 页面滚动
28 | 'onTabItemTap' //当前是 tab 页时 // 点击 tab 时触发 (mpvue 0.0.16 支持)
29 | ]);
30 |
31 | wrap(
32 | App,
33 | {
34 | name: config.APP_NAME,
35 | version: config.VERSION,
36 | pkgName: pkg.name,
37 | domain: config.DOMAIN,
38 | env: config.DEBUG ? 'development' : 'production'
39 | },
40 | appProps
41 | );
42 |
43 | export default {
44 | // 这个字段走 app.json
45 | config: {
46 | pages: ['^pages/index/index', 'pages/sample/sample'], // 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
47 | window: {
48 | backgroundTextStyle: 'black',
49 | navigationBarBackgroundColor: '#ffffff',
50 | navigationBarTitleText: 'WeChat',
51 | navigationBarTextStyle: 'black'
52 | },
53 | tabBar: {
54 | color: '#69707E',
55 | selectedColor: '#69707E',
56 | backgroundColor: '#ffffff',
57 | list: [
58 | {
59 | pagePath: 'pages/index/index',
60 | text: '首页',
61 | iconPath: 'static/images/home.png',
62 | selectedIconPath: 'static/images/home-active.png'
63 | },
64 | {
65 | pagePath: 'pages/sample/sample',
66 | text: '示例1',
67 | iconPath: 'static/images/uc.png',
68 | selectedIconPath: 'static/images/uc-active.png'
69 | },
70 | {
71 | pagePath: 'pages/sample2/sample2',
72 | text: '示例2',
73 | iconPath: 'static/images/uc.png',
74 | selectedIconPath: 'static/images/uc-active.png'
75 | }
76 | ]
77 | },
78 | networkTimeout: {
79 | request: 10000,
80 | downloadFile: 10000
81 | },
82 | debug: false
83 | }
84 | };
85 |
--------------------------------------------------------------------------------
/ts-example/src/mocks/examples.json:
--------------------------------------------------------------------------------
1 | {
2 | "code": 200,
3 | "data": [
4 | {
5 | "title": "sample mpvue wxapp",
6 | "content": "this is a sample of mpvue wxapp project"
7 | },
8 | {
9 | "title": "sample mpvue wxapp2",
10 | "content": "this is a sample of mpvue wxapp project 2"
11 | }
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/ts-example/src/pages/index/index.less:
--------------------------------------------------------------------------------
1 | .container {
2 | position: relative;
3 | background-color: #e7e7e7;
4 | display: flex;
5 | flex-direction: column;
6 | height: 100vh;
7 | & > .section {
8 | flex-shrink: 0;
9 | flex-grow: 0;
10 | }
11 |
12 | .loader {
13 | text-align: center;
14 | margin: 100rpx auto;
15 | img {
16 | width: 60rpx;
17 | height: 60rpx;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ts-example/src/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
99 |
100 |
103 |
--------------------------------------------------------------------------------
/ts-example/src/pages/index/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page, {
6 | state() {
7 | return {
8 | test: 1
9 | };
10 | },
11 | mutations: {
12 | updateTest(state: any, test) {
13 | state.test = test;
14 | }
15 | }
16 | });
17 | /* tslint:enable */
18 |
19 | export default {
20 | config: {
21 | backgroundTextStyle: 'light',
22 | navigationBarBackgroundColor: '#00b2ff',
23 | navigationBarTitleText: '首页',
24 | navigationBarTextStyle: 'white'
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample/README.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | 本页面使用 Vue 默认的组件写法,导出 VueOptions 对象
4 |
5 | ```js
6 | export default {
7 | data() {
8 | return {}
9 | },
10 |
11 | ...
12 | }
13 | ```
14 |
15 | 同样可以使用`Vue.extend`写法,语法类似
16 |
17 | ```js
18 | import Vue from 'vue';
19 |
20 | export default Vue.extend({
21 | data() {
22 | return {};
23 | }
24 | });
25 | ```
26 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
20 |
21 |
27 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | backgroundTextStyle: 'black',
11 | navigationBarBackgroundColor: '#ffffff',
12 | navigationBarTitleText: '示例页面',
13 | navigationBarTextStyle: 'black'
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample2/README.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | 本页面使用 Vue Class 继承式组件写法
4 |
5 | ```js
6 | export default class Sample2 extends Vue {
7 | // ...
8 | }
9 | ```
10 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample2/index.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import { Component } from 'vue-property-decorator';
3 | import board from '@/components/board.vue';
4 |
5 | // 必须以Component装饰器模式指定子组件
6 | @Component({
7 | components: {
8 | board
9 | }
10 | })
11 | export default class Sample2 extends Vue {
12 | // 私有属性方式指定data元素
13 | title: string = '示例页面2';
14 | content: string = '使用TypeScript+Vue Class组件写法';
15 |
16 | // get 方法指定computed的元素
17 | get computed1() {
18 | return 'computed1';
19 | }
20 |
21 | // methods直接写为类方法
22 | method1() {
23 | // do something
24 | }
25 |
26 | // 小程序生命周期
27 | onShow() {
28 | console.log('[Sample2] onShow');
29 | }
30 |
31 | // Vue生命周期
32 | mounted() {
33 | console.log('[Sample2] mounted');
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample2/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
18 |
--------------------------------------------------------------------------------
/ts-example/src/pages/sample2/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | backgroundTextStyle: 'black',
11 | navigationBarBackgroundColor: '#ffffff',
12 | navigationBarTitleText: '示例页面2',
13 | navigationBarTextStyle: 'black'
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/ts-example/src/pages/webview/index.less:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/src/pages/webview/index.less
--------------------------------------------------------------------------------
/ts-example/src/pages/webview/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
77 |
78 |
81 |
--------------------------------------------------------------------------------
/ts-example/src/pages/webview/main.ts:
--------------------------------------------------------------------------------
1 | import Page from './index.vue';
2 | import { WrapPage } from 'common-mpvue';
3 |
4 | /* tslint:disable */
5 | new WrapPage(Page);
6 | /* tslint:enable */
7 |
8 | export default {
9 | config: {
10 | navigationBarTitleText: ''
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/ts-example/src/store/main.ts:
--------------------------------------------------------------------------------
1 | import { VuexStore } from 'common-mpvue';
2 |
3 | export default (function() {
4 | let store: VuexStore = null as any;
5 |
6 | return function createStore() {
7 | const initialState = Object.assign(Object.create(null), {
8 | examples: []
9 | });
10 | if (!store) {
11 | store = new VuexStore({
12 | strict: process.env.NODE_ENV !== 'production',
13 | state: initialState,
14 | mutations: {
15 | // examples
16 | updateExamples(state, examples) {
17 | state.examples = examples;
18 | }
19 | }
20 | });
21 | }
22 |
23 | return store;
24 | };
25 | })();
26 |
--------------------------------------------------------------------------------
/ts-example/src/utils/index.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/src/utils/index.ts
--------------------------------------------------------------------------------
/ts-example/static/images/home-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/home-active.png
--------------------------------------------------------------------------------
/ts-example/static/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/home.png
--------------------------------------------------------------------------------
/ts-example/static/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/loading.gif
--------------------------------------------------------------------------------
/ts-example/static/images/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/success.png
--------------------------------------------------------------------------------
/ts-example/static/images/uc-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/uc-active.png
--------------------------------------------------------------------------------
/ts-example/static/images/uc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/uc.png
--------------------------------------------------------------------------------
/ts-example/static/images/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thundernet8/generator-mpvue-project/fdbfe343d38ede1479a3e6e6e9357aca4afe4c96/ts-example/static/images/warn.png
--------------------------------------------------------------------------------
/ts-example/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target":
4 | "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
5 | "module":
6 | "es2015" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7 | // "lib": [], /* Specify library files to be included in the compilation. */
8 | // "allowJs": true, /* Allow javascript files to be compiled. */
9 | // "checkJs": true, /* Report errors in .js files. */
10 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11 | // "declaration": true, /* Generates corresponding '.d.ts' file. */
12 | // "sourceMap": true, /* Generates corresponding '.map' file. */
13 | // "outFile": "./", /* Concatenate and emit output to single file. */
14 | // "outDir": "./", /* Redirect output structure to the directory. */
15 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16 | // "removeComments": true, /* Do not emit comments to output. */
17 | // "noEmit": true, /* Do not emit outputs. */
18 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */
19 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
20 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
21 |
22 | /* Strict Type-Checking Options */
23 | // "strict": true /* Enable all strict type-checking options. */,
24 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25 | "strictNullChecks": true /* Enable strict null checks. */,
26 | "strictFunctionTypes": true /* Enable strict checking of function types. */,
27 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
28 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
29 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
30 |
31 | /* Additional Checks */
32 | // "noUnusedLocals": true, /* Report errors on unused locals. */
33 | // "noUnusedParameters": true, /* Report errors on unused parameters. */
34 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36 |
37 | /* Module Resolution Options */
38 | "moduleResolution":
39 | "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
40 | "baseUrl":
41 | "src" /* Base directory to resolve non-absolute module names. */,
42 | "paths": {
43 | "@/api/*": ["api/*"],
44 | "@/common/*": ["common/*"],
45 | "@/components/*": ["components/*"],
46 | "@/assets/*": ["assets/*"],
47 | "@/config/*": ["config/*"],
48 | "@/store/*": ["store/*"],
49 | "@/utils/*": ["utils/*"],
50 | "vue": ["mpvue"]
51 | } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
52 | "rootDirs": [
53 | "./src"
54 | ] /* List of root folders whose combined content represents the structure of the project at runtime. */,
55 | "typeRoots": [
56 | "node_modules/@types",
57 | "types"
58 | ] /* List of folders to include type definitions from. */,
59 | // "types": [], /* Type declaration files to be included in compilation. */
60 | "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
61 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
62 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
63 |
64 | /* Source Map Options */
65 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
66 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
67 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
68 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
69 |
70 | /* Experimental Options */
71 | "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
72 | "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/ts-example/types/promise.d.ts:
--------------------------------------------------------------------------------
1 | interface Promise {
2 | finally: (onfinally?: (() => void) | null | undefined) => Promise;
3 | }
4 |
--------------------------------------------------------------------------------
/ts-example/types/shim.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.vue' {
2 | import Vue from 'vue';
3 | export default Vue;
4 | }
5 |
--------------------------------------------------------------------------------
/ts-example/types/vue.d.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import App from 'common-mpvue/types/app';
3 | import { VuexStore } from 'common-mpvue/types/internal';
4 | import { Store } from 'vuex/types';
5 |
6 | interface TabItem {
7 | index: number;
8 | pagePath: string;
9 | text: string;
10 | }
11 |
12 | declare module 'vue/types/options' {
13 | interface ComponentOptions {
14 | /**
15 | * 监听页面加载
16 | */
17 | onLoad?(): void;
18 |
19 | /**
20 | * 监听页面显示
21 | */
22 | onShow?(): void;
23 |
24 | /**
25 | * 监听页面初次渲染完成
26 | */
27 | onReady?(): void;
28 |
29 | /**
30 | * 监听页面隐藏
31 | */
32 | onHide?(): void;
33 |
34 | /**
35 | * 监听页面卸载
36 | */
37 | onUnload?(): void;
38 |
39 | /**
40 | * 监听用户下拉动作
41 | */
42 | onPullDownRefresh?(): void;
43 |
44 | /**
45 | * 页面上拉触底事件的处理函数
46 | */
47 | onReachBottom?(): void;
48 |
49 | /**
50 | *
51 | * @param res 用户点击右上角分享
52 | */
53 | onShareAppMessage?(res): any;
54 |
55 | /**
56 | * 页面滚动
57 | */
58 | onPageScroll?(e);
59 |
60 | /**
61 | * 当前是 tab 页时 // 点击 tab 时触发
62 | */
63 | onTabItemTap?(item);
64 |
65 | /**
66 | * Common-mpvue添加的入口App.vue独有的声明周期,在此声明周期内小程序app已经实例化完成,而其他onShow mounted声明周期内app未实例化完成
67 | */
68 | onLaunched?();
69 | }
70 | }
71 |
72 | declare module 'vue/types/vue' {
73 | interface VueConstructor {
74 | mpType: string;
75 | }
76 |
77 | interface Vue {
78 | /**
79 | * 小程序app实例
80 | */
81 | $app: App;
82 |
83 | /**
84 | * 页面公用的业务Vuex Store
85 | */
86 | $store: Store;
87 | $_store: VuexStore;
88 |
89 | /**
90 | * 当前页面使用的Vuex模块State
91 | */
92 | $state: any;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------