|
1 | | -# vue-cli-plugin-multiple |
2 | | -A plugin for build/watch multiple page entries based on vue-cli |
| 1 | +# vue-cli-plugin-multiple-page |
| 2 | + |
| 3 | +> build/watch multiple page one time for vue-cli |
| 4 | +
|
| 5 | +## Commands |
| 6 | + |
| 7 | +Here are 3 commands for this plugin: |
| 8 | + |
| 9 | +1. `init-config`: initialize `vue.config.js` & `Views.json` two files to your project |
| 10 | +2. `build-multi`: build multiple page in parallel |
| 11 | +3. `watch-multi`: watch multiple page in parallel |
| 12 | + |
| 13 | +You can use `vue-cli-service [command]` in your project |
| 14 | + |
| 15 | +### init-config |
| 16 | + |
| 17 | +The command will be generates `vue.config.js`、`Views.json` files if your project haven't corresponding files |
| 18 | + |
| 19 | +- [vue.config.js](./template/vue.config.js) |
| 20 | +- [Views.json](./template/Views.json) |
| 21 | + |
| 22 | +### build-multi |
| 23 | + |
| 24 | +The command will be build you entries where above generated configurations |
| 25 | +, and you can specify the entry by pass `--key` option, e.g: |
| 26 | + |
| 27 | +``` sh |
| 28 | +vue-cli-service build-multi --key page,page1 # build page,page1 two entries |
| 29 | +``` |
| 30 | + |
| 31 | +`Views.json`: |
| 32 | + |
| 33 | +``` json |
| 34 | +{ |
| 35 | + "basePath": "resources/assets/js/views", |
| 36 | + "destBasePath": "public/js/v", |
| 37 | + "entry": { |
| 38 | + "page": { |
| 39 | + "srcPath": "page", |
| 40 | + "name": "index", |
| 41 | + "output": "page-index", |
| 42 | + "description": "test page" |
| 43 | + }, |
| 44 | + "page1": { |
| 45 | + "srcPath": "page1", |
| 46 | + "name": "index", |
| 47 | + "output": "page1-index", |
| 48 | + "description": "test page1" |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +The final result of above configuration will be generates: |
| 55 | + |
| 56 | +- entry: [`yourProject/resources/assets/js/views/page/index.js`, `yourProject/resources/assets/js/views/page1/index.js`] |
| 57 | +- output: [`yourProject/public/js/v/page-index/index.js`, `yourProject/public/js/v/page1-index/index.js`] |
| 58 | + |
| 59 | +### watch-multi |
| 60 | + |
| 61 | +The command like `build-multi`, but it in watch mode |
| 62 | + |
| 63 | +## Custom Config |
| 64 | + |
| 65 | +This plugin provide custom config file that you can specify entries manually in Programmatically. You can create a file named `multiple-page.config.js`, that content like below: |
| 66 | + |
| 67 | +``` js |
| 68 | +const path = require('path') |
| 69 | +const resolve = name => path.resolve(__dirname, name) |
| 70 | +const basePath = resolve('resources/assets/js/views') |
| 71 | +const outputPath = resolve('public/js/v') |
| 72 | + |
| 73 | +module.exports = { |
| 74 | + page: { |
| 75 | + entry: path.join(basePath, 'page/index.js'), |
| 76 | + output: path.join(outputPath, 'page-index'), |
| 77 | + description: 'test page', |
| 78 | + extract: true, |
| 79 | + chunkName: 'index' |
| 80 | + }, |
| 81 | + page1: { |
| 82 | + entry: path.join(basePath, 'page1/index.js'), |
| 83 | + output: path.join(outputPath, 'page1-index'), |
| 84 | + description: 'test page1', |
| 85 | + chunkName: 'index' |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +If you have both files (`Views.json`、`multiple-page.config.js`) in your root directory, The `multiple-page.config.js` file have a higher priority. |
| 91 | + |
| 92 | +## TODO |
| 93 | + |
| 94 | +- [] test cases |
0 commit comments