|
1 |
| -# nativescript-vue-cli-plugin |
| 1 | +# nativescript-vue-cli-plugin |
| 2 | + |
| 3 | +Nativescript-Vue Plugin for [[email protected]](https://github.com/vuejs/vue-cli) |
| 4 | + |
| 5 | +This plugin will integrate [Nativescript-Vue](https://nativescript-vue.org/) into new and existing Vue projects. Additionally, it will allow for the choice of developing for Native only environments or Native __and__ Web environments under a single project structure. In addition, choosing to integrate [Nativescript-Vue-Web](https://github.com/Nativescript-Vue-Web/Nativescript-Vue-Web), will allow for the development of Web components with a NativeScript-Vue like syntax that has the benefit of allowing for the sharing of components between the Native and Web sides of the project. This helps reduce the amount of code, maintenence needs, and the amount of time needed for development activities. |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +If vue-cli 3 is not yet installed, first follow the instructions here: https://github.com/vuejs/vue-cli |
| 10 | + |
| 11 | +**Tip**: If you don't want to overwrite your current vue-cli 2 setup because you still need `vue init`, [then try this](https://cli.vuejs.org/guide/creating-a-project.html#pulling-2-x-templates-legacy). |
| 12 | + |
| 13 | +Generate a project using vue-cli 3.0 |
| 14 | +``` |
| 15 | +vue create my-app |
| 16 | +``` |
| 17 | + |
| 18 | +Before installing the Nativescript-Vue CLI 3 Plugin, make sure to commit or stash changes in case you need to revert. |
| 19 | + |
| 20 | +To install the Nativescript-Vue CLI 3 Plugin... |
| 21 | +``` |
| 22 | +cd my-app |
| 23 | +npm install --save-dev vue-cli-plugin-nativescript-vue |
| 24 | +vue invoke vue-cli-plugin-nativescript-vue |
| 25 | +``` |
| 26 | + |
| 27 | +## Invocation Prompts |
| 28 | +1. Enter a unique application identifier |
| 29 | + * Accpeting the default is fine for testing |
| 30 | +2. Use HTML5 history mode? (Default: hash mode) |
| 31 | + * Required parameter for the cli core generator when vue-router is used |
| 32 | +3. Is this a brand new project? (Default: No) |
| 33 | + * By choosing `No`, which is the default, the plugin will try and be as non-destructive as possible to an existing project. It will do this by adding a folder into root named `ns-example` and add files into there to provide examples of how a project would change. |
| 34 | + * These changes will factor in answers to the other questions and adjust accordingly. Regardless of the answer, the plugin will install packages and adjust `package.json` as necessary to prep the project. |
| 35 | +4. Dual Native AND Web development experience or a Native only? (Default: Dual) |
| 36 | + * By default, the plugin will assume you want to develop for the Web and Native environments within the same project. As such, there will be two sides to the project where web environments will be actively developed within `/src` and Native environments will be developed within `/app`. |
| 37 | + * Warning: Choosing to develop for Native only will move the main entry point of the project and development folder to `/app`, copy necessary files and then delete `/src`. |
| 38 | + * By choosing `Dual`, you will be able to bring your own component framework into the web portion of the project. `NativeScript-Vue` [cannot use vue-router](https://nativescript-vue.org/en/docs/routing/vue-router/) currently, so you will have to provide your own manual routing. The templated options deployed with the plugin will show how to do basic manual routing. |
| 39 | +5. Use [Nativescript-Vue-Web](https://github.com/Nativescript-Vue-Web/Nativescript-Vue-Web) to develop web components with `Nativescript-Vue` syntax? (Default: No) |
| 40 | + * This prompt should only appear if you have chosen to develop in the Dual Web and Native environments. |
| 41 | + * By chosing `Use Nativescript-Vue-Web component framework`, it will effecively integrate a web component framework that will allow you to develop components that can be used in the Web and Native side of the project. It uses `NativeScript-Vue` like syntax on components which will allow for the sharing of components between NativeScript and Web. |
| 42 | +6. What type of template do you want to start with? (Default: Simple) |
| 43 | + * Simple is just a simple setup with a header and basic routing. |
| 44 | + * Sidebar (currently disabled), will allow you to start with a project that includes a fixed header and pop-out sidebar menu. |
| 45 | + * We expect to add more templates in the future as use cases come up. |
| 46 | + |
| 47 | +## Running the project |
| 48 | +You will have several options in serving and building the project: |
| 49 | +1. `npm run serve:web` |
| 50 | +2. `npm run serve:android` |
| 51 | +3. `npm run serve:ios` |
| 52 | +4. `npm run build:web` |
| 53 | +5. `npm run build:android` |
| 54 | +6. `npm run build:ios` |
| 55 | + |
| 56 | +The basic `serve` and `build` options should be similar to what is in a CLI 3 project except the added options to dictate which kind of environment you are using: `web`, `android` or `ios`. Please note that when building web projects, they will output to `dist` and when building native projects, they will output to `platforms\android` or `platforms\ios` depending on which you are building at the time. |
| 57 | + |
| 58 | +#Webpack related information |
| 59 | +The options passes in at `npm run` will dictate what webpack config is provided. The first choice webpack will make is if this is a `web` or `native` environment. Then, if it's a `native` environment, it will determine choices to be made between `ios` and `android`. |
| 60 | + |
| 61 | +Each time the project is built or served, the plugin will copy the latest webpack config from the cli to the root of your project. When you build a project, it will clean-up this file at the end, but just serving the project will not. This is an issue with [nativescript-dev-webpack](https://github.com/NativeScript/nativescript-dev-webpack) and cannot be overcome at this time. |
| 62 | + |
| 63 | +#### Inspecting the Webpack config |
| 64 | +If you'd like to see what the webpack config is doing then you can run the following: |
| 65 | +`vue inspect --mode development.web > output.js` and the `output.js` file in root will show you what's going on. Subtitute `development.android` or `production.ios`, etc to see the different configs based on the environmental variables. |
| 66 | + |
| 67 | +#### Aliases |
| 68 | +Prebuilt in the webpack config are several aliases that you can use. Here is a table listing out the various alias and the folder they use based on the environment chosen: |
| 69 | + |
| 70 | +| Alias | Native | Web | |
| 71 | +| ---------- | --------------- | --------------- | |
| 72 | +| ~ | /app | /src | |
| 73 | +| @ | /app | /src | |
| 74 | +| src | /src | /src | |
| 75 | +| assets | /src/assets | /src/assets | |
| 76 | +| components | /src/components | /src/components | |
| 77 | +| fonts | /src/fonts | /src/fonts | |
| 78 | +| root | / | / | |
| 79 | + |
| 80 | + |
| 81 | +## For TypeScript enabled projects |
| 82 | +If your CLI 3 project has TypeScript enabled, then the plugin will attempt to give you a very basic TypeScript version of the template you choose. When you invoke the plugin and the template generator makes changes, you will notice the `*.d.ts` files that are usually in `src` will be moved to root so that they can be referenced inside of `src` and `app`. The plugin's webpack integration will ensure these files are referenced correctly at compile and runtimes. |
| 83 | + |
| 84 | +## For Native environment development |
| 85 | +It should be noted that the plugin will give you the ability to develop generic SFC's (\*.native.vue) to be used in Android and IOS, or if you need to differentiate between Android (\*.android.vue) and IOS (\*.ios.vue) then you can change the SFC's extension to map to the environment you choose. |
| 86 | + |
| 87 | +At `serve` or `build` in conjunction with the mode such as `android` or `ios`, it will filter which files are looked at. For instance, if you do `npm run serve:android`, then it will look for `*.native.vue` and `*.android.vue` files and ignore `*.ios.vue` files entirely. Conversely, it will do the same when your are doing the same for `ios` and will ignore `*.android.vue` files. |
| 88 | + |
| 89 | +This will allow you to develop generic native components under the `*.native.vue` file extension, but in special cases, it may require you to do platform specific components. Use the corrosponding file extension to allow this to happen. |
| 90 | + |
| 91 | +## Sharing components and assets between environments |
| 92 | +If you want to use common components and assets between `web`, `android` and `ios`, you can do that. Based on directory structures and webpack aliases setup by the plugin, it is __highly__ suggested you place these common items in the `src` folder directory structure. For `assets`, place them in `src/assets` and for components, place them in `src/components`. At compile time, assets will be copied to the output directory's `assets` folder and can be universally accessed across environments via something like `~/assets/logo.png`. For components, they can be universally accessed via something similar to `components/HelloWorld`. |
| 93 | + |
| 94 | + |
| 95 | + |
0 commit comments