UNPKG

2.5 kBMarkdownView Raw
1# Build tools for FE
2
3Universal front-end automation tools
4
5## Install
6
7```bash
8npm install qu-build -g
9```
10
11## Usage
12
13```bash
14Usage: qu-build [options]
15
16Options:
17
18 -v, --version output the version number
19 -o, --output-path <path> output path
20 -w, --watch [delay] watch file changes and rebuild
21 -d, --dev start develop server
22 -p, --port [port] develop server port, default is 8080
23 -b, --build build this project
24 -t, --test test this project, use jest
25 --hash build with hash and output map.json
26 --publicPath <publicPath> publicPath for webpack
27 --devtool <devtool> sourcemap generate method, default is null
28 --config <path> custom config path, default is webpack.config.js
29 --no-compress build without compress (default: true)
30 --json running webpack with --json, ex. result.json
31 --verbose run with more logging messages.
32 -h, --help output usage information
33
34
35 Commands:
36
37 init generate a new project from a template, templates: [vue, pages]
38
39```
40
41## Template Create
42
43```bash
44# vue template project
45qu-build init vue project-name
46
47# multi page template project
48qu-build init pages project-name
49```
50
51## Mock
52
53Use mockjs, mock storage directory `./src/api`, support `.js`,`.json`.
54
55```javascript
56/**
57 * @url /order/addOrderComment.do
58 *
59 */
60module.exports = function (req) {
61 return {
62 success: Math.random() < 0.5 ? false : true,
63 msg: '@word',
64 code: Math.random() < 0.5 ? -200 : 0,
65 };
66}
67```
68or
69```json
70{
71 "msg": "@word",
72 "code": 200,
73}
74```
75
76If you use `jsonp`, request parameters increase `callback`. The return data will be `jsonp`.
77
78```javascript
79/**
80 * http://localhost:8080/?callback=jQuery1513158553653
81 */
82jQuery1513158553653({
83 "msg": "abc",
84 "code": 200,
85})
86```
87
88## Directory
89
90```bash
91./public # static resource directory;
92./api # mock directory;
93./src # development source code;
94./package.json # project info
95./webpack.config.js # custom webpack configuration
96```
97
98## Config
99
100webpack.config.js
101
102```javascript
103// get webpack
104var webpack = require('qu-build/lib/webpack');
105
106module.exports = function(webpackConfig) {
107 webpackConfig.plugins.push(
108 new webpack.DefinePlugin({
109 __DEV__: JSON.stringify('true')
110 });
111 );
112 return webpackConfig;
113};
114```
\No newline at end of file