You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several Updates to template structures and styling (#21)
* removed app dir for dual native and web projects
* Custom loader implementation (#18)
* Add vue-custom-template-loader to the webpack config.
* Add a <template-native> custom block to the App.vue, instead of having 4 files.
* Include vue-custom-template-loader in the app package.json when invoking the plugin.
* ADd vue-custom-template-loader in the web case.
* Some minor fixes.
* Different App.vue code when vue-router is not enabled.
* Do not need to import some components if vue-router is not used.
* Fixed a missing msg data for the no vue-router case.
* Some fixes in the App.vue template.
* No need for that App.vue to App.native.vue replacement.
* More fixes.
* Try to fix an error as the <template> block should not be compiled on native.
* Change the approach by replacing the <template web> and <template native> section before compiling the templates.
* Typo fix.
* Add string-replace-loader dev dependency
* Fix regex for string replacement.
* Remove the strict way and fix the regex.
* Typo fixed.
* Allow the `<style native>` block for writting styles only for native. Same for `<style web>`.
* Fix the template when used with nativescript-vue-web.
* Some documentation about the new `<template native>`, `<template web>`, `<style native>` and `<style web>`
* More robust <template> and <style> search-and-replace logic.
* Fix some issues with the NS-vue-web template. Removed Home.*.vue and About.*.vue templates.
* Removed About.*.vue and Home.*.vue files on the template.
* Minor fixes.
* Moved NVW into its own template
Removed NVW as a separate prompt question and into template choice
Cleaned up Simple and NVW templates
Changed Native only projects to use main.js instead of main.native.js
* Tslint errors (#19)
* Fix tslint errors in the simple template
* Fix tslint errors after generating app code if using Typescript.
* Add tslint module which fix the tslint errors on demand.
* Use NS 5.2 instead of 5.1 (#20)
* Updated Readme's and bumped to 0.0.5
* Added stylus and less support
reconfigured style files to be easier to maintain over time
added filter in generator to only add styles that work with preprocessor
edited templates to accomodate less and stylus
changed webpack regexp that removes web/native blocks
* Addressed additional styling issues in templates.
Fixed nvw template with all the new styling options
Copy file name to clipboardExpand all lines: README.md
+73-17
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,76 @@ Nativescript-Vue Plugin for [[email protected]](https://github.com/vuejs/vue-cli)
4
4
5
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
6
7
+
## Sharing logic in a single Web and Native capable component
8
+
The key feature of this plugin is that it will allow you to compose SFC's that contain both Web and Native structures in them. If your component has exactly the same logic (`<script>` block) but you want different templates for web and native, you can use the special `<template web>` and `<template native>`. Also, if you need define different styles you can use `<style web>` and `<style native>`.
9
+
10
+
An example of this would be the following Vue component:
msg: `Mode=${appMode} and Platform=${process.env.VUE_APP_PLATFORM}`,
39
+
};
40
+
},
41
+
}
42
+
</script>
43
+
<style web>
44
+
w-page {
45
+
padding: 1rem;
46
+
}
47
+
</style>
48
+
<style native>
49
+
ActionBar {
50
+
color: red;
51
+
}
52
+
</style>
53
+
```
54
+
55
+
### Optional Seperation of concerns for Web and Native SFC's
56
+
If you want complete seperation of concerns between Web and Native for components, core logic and styling, you can also provide an alternate file naming scheme in your project. The name will dictate which mode (Web or Native) and platform (Android or IOS) the file will be used with. The same overall schema will work for `.vue`, `.js`, `.ts`, `.scss` and `.css` files.
57
+
58
+
| File Type | Android __and__ IOS | Android only | IOS only | Web only |
Webpack will handle figuring out which files to include based on the `npm run` command syntax you pass in. You can also mix and match this file naming schema with the `web` or `native` tag options mentioned above.
67
+
68
+
At `serve` or `build` in conjunction with the mode such as `android` or `ios`, Webpack 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 you are working with `ios` and will ignore `*.android.vue` files.
69
+
70
+
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, core logic and styling. Use the corrosponding file extension to allow this to happen.
71
+
72
+
If you are building for web, then just `*.vue` will work and if you are building for a Native __only__ project, then `*.vue` will work as well as the previous options mentioned.
73
+
74
+
## Sharing components and assets between Native and Web SFC's
75
+
If you want to use common components and assets between `web`, `android` and `ios`, you can do that. 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`.
76
+
7
77
## Install
8
78
9
79
If vue-cli 3 is not yet installed, first follow the instructions here: https://github.com/vuejs/vue-cli
* 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` unless you choose to integrate `Nativescript-Vue-Web` and all files will be placed in `/src`.
37
107
* Warning: Choosing to develop for Native only will move the main entry point of the project and development folder to `/app`, it will copy the necessary files and then delete `/src`.
38
108
* 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 `Yes. 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)
109
+
5. What type of template do you want to start with? (Default: Simple)
43
110
* Simple is just a simple setup with a header and basic routing.
111
+
*[Nativescript-Vue-Web](https://github.com/Nativescript-Vue-Web/Nativescript-Vue-Web) - The Simple template, but with NS-Vue like syntax for web components. This option should only appear if you have chosen to develop in the Dual Web and Native environments. This option 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.
44
112
* Sidebar (currently disabled), will allow you to start with a project that includes a fixed header and pop-out sidebar menu.
45
113
* We expect to add more templates in the future as use cases come up.
46
114
@@ -63,7 +131,7 @@ You will have the standard options for debugging available to you as you would w
63
131
64
132
You should then be able to attach the Chrome debugger as you normally would via the [NativeScript docs](https://docs.nativescript.org/angular/tooling/debugging/chrome-devtools).
65
133
66
-
You should also be able to debug directly in VSCode. The [NativeScript VSCode Extension docs](https://docs.nativescript.org/angular/tooling/visual-studio-code-extension) are a good place to start with understanding how to do this. However, you will need to modify your `launch.json` file to force `tns` to work properly with VUE CLI 3.
134
+
You should also be able to debug directly in VSCode. The [NativeScript VSCode Extension docs](https://docs.nativescript.org/angular/tooling/visual-studio-code-extension) are a good place to start with understanding how to do this. However, you will need to modify your `launch.json` file to force `tns` to work properly with VUE CLI 3.
67
135
68
136
Your `launch.json` file should look something like below. Notice the different in the `tnsArgs` line that is different than what is in the documentation link above.
69
137
```
@@ -172,15 +240,3 @@ Prebuilt in the webpack config are several aliases that you can use. Here is a
172
240
173
241
## For TypeScript enabled projects
174
242
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 `/types`. The plugin's webpack integration will ensure these files are referenced correctly at compile and runtimes.
175
-
176
-
There will also be additional `tsconfig.json` files added into the root that allow for specific configurations depending on the type of environment you are building for. You will see a `tsconfig.web.json` and a `tsconfig.native.json` file that extend the base `tsconfig.json` file in root. The plugin's webpack integration will ensure the correct `tsconfig` file is referenced at runtime.
177
-
178
-
## For Native environment development
179
-
It should be noted that the plugin will give you the ability to develop generic SFC's (\*.native.vue) to be used in both 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.
180
-
181
-
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.
182
-
183
-
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.
184
-
185
-
## Sharing components and assets between environments
186
-
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`.
It is __highly, highly, highly suggested__ that you copy/paste the `simple` template in its entirety and then rename the copied directory. It will make it much easier for you to get started using the existing logic in the generator. Modifications to the existing generator logic will be considered for PR, but will have to go through rigourous testing to ensure the changes do not break all pre-existing templates.
3
+
Want to submit a PR for a new template? Read below.
4
+
5
+
It is __highly, highly, highly suggested__ that you copy/paste the `simple` template in its entirety and then rename the copied directory. It will make it much easier for you to get started using the existing logic in the generator. Modifications to the existing generator logic will be considered for PR, but will have to go through rigourous testing to ensure the changes do not break all pre-existing templates.
4
6
5
7
If you want to add additional templates to the plugin, then here's the information on how to do it:
6
8
7
-
1. Create a new option to the prompt question #6 concerning which template you'd like to deploy.
9
+
1. Create a new option to the prompt question #5 concerning which template you'd like to deploy.
8
10
* The value for the template should be kept simple and easy.
9
11
2. Create a new directory under `/generator/templates`.
10
-
* The directory name should __exactly match__ the value from #1. For example if the value from #1 is `sidebar`, then the directory structure would be `/generator/templates/sidebar`
11
-
3. The new template directory __must__ have a first-level subdirectory named `without-nvw`. 4. Within the `without-nvw` directory, it should have the following:
12
-
*`src` directory
13
-
*`app` directory
14
-
*`tsconfig.native.json` & `tsconfig.web.json` (so as to enable TypeScript support)
15
-
5. Inside the `without-nvw\src` directory, you should add the following in an effort to give the template feature consistancy to the other templates:
12
+
* The directory name should __exactly match__ the value from #1. For example if the value from #1 is `simple`, then the directory structure would be `/generator/templates/simple`
13
+
3. The new template directory __must__ have a single first-level subdirectory named `src`.
14
+
4. Inside the `src` directory, you should add the following in an effort to give the template feature consistancy to the other templates:
16
15
* router.js
17
-
* main.js
16
+
* main.js
17
+
* main.native.js (the NS-Vue project entry point)
18
+
* package.json (this is the standard NativeScript-Vue package.json file. Just copy/paste from the simple template)
18
19
* App.vue
19
20
* views/About.vue (optional)
20
21
* views/Home.vue (optional)
21
22
* components/HelloWorld.vue (optional)
22
-
* assets/logo.png (optional, but highly encouraged to prove images are loading)
23
-
5. Inside the `without-nvw\app` directory, you should add the following in an effort to give the template feature consistancy to the other templates:
24
-
* package.json (as usual for Nativescript-Vue projects)
25
-
* main.js
26
-
* App.native.vue
27
-
* App.ios.vue
28
-
* App.android.vue
29
-
* views/About.native.vue (optional)
30
-
* views/About.ios.vue (optional)
31
-
* views/About.android.vue (optional)
32
-
* views/Home.native.vue (optional)
33
-
* views/Home.ios.vue (optional)
34
-
* views/Home.android.vue (optional)
35
23
* components/HelloWorld.native.vue (optional)
36
24
* components/HelloWorld.ios.vue (optional)
37
25
* components/HelloWorld.android.vue (optional)
38
26
* assets/logo.png (optional, but highly encouraged to prove images are loading)
39
27
40
-
If you want to include support for `Nativescript-Vue-Web` within your template, then you can also follow the pattern included in the `simple` template. You will need to:
41
-
1. Add a first-level subdirectory named `with-nvw`.
42
-
2. Within the `with-nvw` directory you will only need to add a `src` directory. You will __not__ need an `app` directory. Again, follow the `simple` template pattern.
43
-
3. Within `src`, you will essentially merge everything that is in the `without-nvw` side of the template. The one main difference is that the `main.js` file from the `app` directory will have to be named `main.native.js`.
44
-
45
-
Concerning the two `tsconfig` files in the base of the template directory. These are necessary to ensure TypeScript enabled projects will work correctly. If your directory structure within your template is different than what is in the `simple` template, then you will need to adjust the two `tsconfig` files to account for those differences. Again, it is __highly encouraged__ that you don't deviate from the directory structure provided by the `simple` template.
46
-
47
-
If you add any of the optional files within the `app` directory structure, then you should make sure you have a \*.native.vue, \*.android.vue and \*.ios.vue example for each SFC. It would also be beneficial within each of those to have a way to identify to the developer which file is being used at compile time. Take a look at the `simple` template's `app\views\about.*.vue` examples to see a basic example of this.
48
-
49
28
Within the \*.vue files you will find [ejs](https://github.com/mde/ejs) syntax that will enable you to differentiate between TypeScript and non-TypeScript projects. Any new templates added to the project __must__ demonstrate they work across these options or the PR to add the template will be rejected.
50
29
51
30
### Word of warning concerning using EJS templates with Prettier
52
-
Prettier does not support EJS templates and if you have Prettier automatically fix all issues in a `*.vue` file, then you will run the risk of it overwriting sections of the template from one `if` statement to the `else` side of the statement. Pay close attention to this specifically in your `script` tags as it relates to the TypeScript vs. non-TypeScript parts of the template. Whichever one comes first in the `if` statement will overwrite the section after the `else` statement.
31
+
Prettier does not support EJS templates and if you have Prettier automatically fix all issues in a `*.vue`template file, then you will run the risk of it overwriting sections of the template from one `if` statement to the `else` side of the statement. Pay close attention to this specifically in your `script` tags as it relates to the TypeScript vs. non-TypeScript parts of the template. Whichever one comes first in the `if` statement will overwrite the section after the `else` statement.
0 commit comments