Skip to content

Commit 2f3cb2d

Browse files
Added debug commands (#16)
Added preview commands cleaned up commented out lines
1 parent b699c88 commit 2f3cb2d

File tree

3 files changed

+97
-52
lines changed

3 files changed

+97
-52
lines changed

README.md

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,90 @@ You will have several options in serving and building the project:
5353
5. `npm run build:android`
5454
6. `npm run build:ios`
5555

56+
5657
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.
5758

59+
### Debugging your project
60+
You will have the standard options for debugging available to you as you would with just `tns`. You can do the following to debug Native versions of your app.
61+
1. `npm run debug:android`
62+
2. `npm run debug:ios`
63+
64+
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+
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.
67+
68+
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+
```
70+
{
71+
"version": "0.2.0",
72+
"configurations": [
73+
{
74+
"name": "Launch on iOS",
75+
"type": "nativescript",
76+
"request": "launch",
77+
"platform": "ios",
78+
"appRoot": "${workspaceRoot}",
79+
"sourceMaps": true,
80+
"watch": true,
81+
"tnsArgs":[" --bundle --env.development cross-env-shell VUE_CLI_MODE=development.ios"]
82+
},
83+
{
84+
"name": "Attach on iOS",
85+
"type": "nativescript",
86+
"request": "attach",
87+
"platform": "ios",
88+
"appRoot": "${workspaceRoot}",
89+
"sourceMaps": true,
90+
"watch": false
91+
},
92+
{
93+
"name": "Launch on Android",
94+
"type": "nativescript",
95+
"request": "launch",
96+
"platform": "android",
97+
"appRoot": "${workspaceRoot}",
98+
"sourceMaps": true,
99+
"watch": true,
100+
"tnsArgs":[" --bundle --env.development cross-env-shell VUE_CLI_MODE=development.android"]
101+
},
102+
{
103+
"name": "Attach on Android",
104+
"type": "nativescript",
105+
"request": "attach",
106+
"platform": "android",
107+
"appRoot": "${workspaceRoot}",
108+
"sourceMaps": true,
109+
"watch": false
110+
},
111+
{
112+
"type": "chrome",
113+
"request": "launch",
114+
"name": "web: chrome",
115+
"url": "http://localhost:8080",
116+
"webRoot": "${workspaceFolder}/src",
117+
"breakOnLoad": true,
118+
"sourceMapPathOverrides": {
119+
"webpack:///src/*": "${webRoot}/*"
120+
}
121+
},
122+
]
123+
}
124+
```
125+
You will also need to modify your `vue.config.js` file to include a `webpack-chain` statement that will setup your source map. It should look something like this:
126+
```
127+
module.exports = {
128+
chainWebpack: config => {
129+
config
130+
.devtool('inline-source-map')
131+
}
132+
}
133+
```
134+
135+
### Previewing your Project
136+
You should be able to use the NativeScript Playground and Preview Apps via the following npm statements:
137+
1. `npm run preview:android`
138+
2. `npm run preview:ios`
139+
58140
#### --env command line recognition
59141
Basic support for passing the `env` command line option is in place, but has a slightly different syntax since we're working with the CLI 3 webpack infrastructure. To inject items into `env` at run-time, you will need to add `-- --env.option` Where option is one of the recognized options that Nativescript-Vue and this project supports.
60142
An example of this would be something like this: `npm run serve:android -- --env.production`. This would allow you to serve up a Production build of your Android app versus just running `npm run serve:android` which would serve a Development version of the same.
@@ -66,13 +148,11 @@ Each time the project is built or served, the plugin will copy the latest webpac
66148

67149
#### Inspecting the Webpack config
68150
If you'd like to see what the webpack config is doing then you can run one of the following:
69-
1. `npm run inspect:android`
70-
2. `npm run inspect:ios`
71-
3. `npm run inspect:web`
72-
73-
These will default to showing you the Development version of the webpack config. You can pass in the `-- --env.production` option to see the Production version of the config.
151+
1. `vue inspect -- --env.android > out-android.js`
152+
2. `vue inspect -- --env.ios > out-android.js`
153+
3. `vue inspect -- --env.web > out-web.js`
74154

75-
If you'd like to control this on your own and not use the provided `npm scripts` then you can do something like: `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.
155+
These will default to showing you the Development version of the webpack config. You can pass in the `-- --env.production` option to see the Production version of the config. Subtitute `development.android` or `production.ios`, etc to see the different configs based on the environmental variables.
76156

77157
#### Aliases
78158
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:
@@ -85,6 +165,7 @@ Prebuilt in the webpack config are several aliases that you can use. Here is a
85165
| assets | /src/assets | /src/assets |
86166
| components | /src/components | /src/components |
87167
| fonts | /src/fonts | /src/fonts |
168+
| styles | /src/styles | /src/styles |
88169
| root | / | / |
89170

90171

generator/index.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ const replace = require('replace-in-file');
66
const newline = process.platform === 'win32' ? '\r\n' : '\n';
77

88
module.exports = async (api, options, rootOptions) => {
9-
// console.log('options.isNativeOrDual - ', options.isNativeOrDual);
10-
// console.log('options.isNVW - ', options.isNVW);
11-
// console.log('options.isNewProject - ', options.isNewProject);
12-
// console.log('options.templateType - ', options.templateType);
13-
14-
// console.log('usingTS - ', api.hasPlugin('typescript'));
15-
// console.log('usingBabel - ', api.hasPlugin('babel'));
16-
// console.log('rootOptions.cssPreprocessor - ', rootOptions.cssPreprocessor);
17-
189
if (options.isNVW === undefined) options.isNVW = false;
1910

2011
const genConfig = {
@@ -62,10 +53,6 @@ module.exports = async (api, options, rootOptions) => {
6253
applicationLicense: api.generator.pkg.license || 'MIT',
6354
applicationId: options.applicationId,
6455
historyMode: options.historyMode,
65-
// doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript'),
66-
// usingBabel: api.hasPlugin('babel'),
67-
// usingTS: api.hasPlugin('typescript'),
68-
// usingNVW: options.isNVW
6956
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript') ? true : false,
7057
usingBabel: api.hasPlugin('babel') ? true : false,
7158
usingTS: api.hasPlugin('typescript') ? true : false,
@@ -93,8 +80,13 @@ module.exports = async (api, options, rootOptions) => {
9380
'remove-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance post',
9481
'serve:android': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns run android --bundle --env.development',
9582
'serve:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.ios tns run ios --bundle --env.development',
96-
'inspect:android': 'npm run setup-webpack-config && vue inspect -- --env.android > out-android.js',
97-
'inspect:ios': 'npm run setup-webpack-config && vue inspect -- --env.ios > out-ios.js',
83+
// 'inspect:android': 'npm run setup-webpack-config && vue inspect -- --env.android > out-android.js',
84+
// 'inspect:ios': 'npm run setup-webpack-config && vue inspect -- --env.ios > out-ios.js',
85+
'debug:android': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns debug android --bundle --env.development',
86+
'debug:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.ios tns debug ios --bundle --env.development',
87+
'preview:android':
88+
'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns preview --bundle --env.development --env.android',
89+
'preview:ios': 'npm run setup-webpack-config && cross-env-shell VUE_CLI_MODE=development.android tns preview --bundle --env.development --env.ios',
9890
'setup-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance pre'
9991
},
10092
dependencies: {
@@ -115,7 +107,7 @@ module.exports = async (api, options, rootOptions) => {
115107
scripts: {
116108
'serve:web': 'vue-cli-service serve --mode development.web --env.development --env.web',
117109
'build:web': 'vue-cli-service build --mode production.web --env.production --env.web',
118-
'inspect:web': 'npm run setup-webpack-config && vue inspect -- --env.web > out-web.js'
110+
//'inspect:web': 'npm run setup-webpack-config && vue inspect -- --env.web > out-web.js'
119111
}
120112
});
121113

@@ -306,9 +298,7 @@ module.exports = async (api, options, rootOptions) => {
306298

307299
// we need to edit the tsconfig.json file in /app
308300
// for a Native only project to remove references to /src
309-
//////if (options.isNativeOrDual === 'native') {
310301
tsconfigSetup(options, genConfig.dirPathPrefix, genConfig.nativeAppPathModifier);
311-
//////}
312302
}
313303

314304
// the main difference between New and Existing for this section is

index.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,18 @@ module.exports = (api, projectOptions) => {
7474
return all;
7575
};
7676
const env = flags.reduce(addOption, {});
77-
//console.log('env - ', env);
7877

7978
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || (env.web && 'web'));
80-
//console.log('platform - ', platform);
8179

8280
// if (!platform) {
8381
// throw new Error('You need to provide a target platform!');
8482
// }
8583

8684
const projectRoot = api.service.context;
87-
//console.log('projectRoot - ', projectRoot);
8885
const isNVW = fs.pathExistsSync(resolve(projectRoot, 'src', 'main.native' + jsOrTs));
89-
//console.log('isNVW - ', isNVW);
90-
9186
const appMode = platform === 'android' ? 'native' : platform === 'ios' ? 'native' : 'web';
92-
//console.log('appMode - ', appMode);
93-
94-
//process.env.VUE_APP_MODE = appMode;
9587

9688
projectOptions.outputDir = join(projectRoot, appMode === 'web' ? 'dist' : nsWebpack.getAppPath(platform, projectRoot));
97-
//console.log('dist - ', projectOptions.outputDir);
9889

9990
return appMode === 'web'
10091
? webConfig(api, projectOptions, env, jsOrTs, projectRoot, isNVW)
@@ -117,7 +108,6 @@ const nativeConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW, plat
117108
// Default destination inside platforms/<platform>/...
118109
const dist = projectOptions.outputDir;
119110
const appResourcesPlatformDir = platform === 'android' ? 'Android' : 'iOS';
120-
//console.log('appResourcesPlatformDir - ', appResourcesPlatformDir);
121111

122112
const {
123113
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -139,20 +129,13 @@ const nativeConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW, plat
139129
const externals = (env.externals || []).map((e) => {
140130
return new RegExp(e + '.*');
141131
});
142-
//console.log('externals - ', externals);
143132

144133
const mode = production ? 'production' : 'development';
145-
// // // // console.log('mode - ', mode);
146134

147135
const appFullPath = resolve(projectRoot, appPath);
148-
// // // // console.log('appFullPath - ', appFullPath);
149136
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
150-
// // // // console.log('appResourcesFullPath - ', appResourcesFullPath);
151-
152137
const entryModule = nsWebpack.getEntryModule(appFullPath);
153-
// // // // console.log('entryModule - ', entryModule);
154138
const entryPath = `.${sep}${entryModule}`;
155-
// // // // console.log('entryPath - ', entryPath);
156139

157140
console.log(`Bundling application for entryPath ${entryPath}...`);
158141

@@ -759,11 +742,7 @@ const webConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW) => {
759742
} = env;
760743

761744
const mode = production ? 'production' : 'development';
762-
763-
// const appFullPath = resolve(projectRoot, appPath);;
764-
// // // // // console.log('appFullPath - ', appFullPath);
765745
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
766-
// // // // console.log('appResourcesFullPath - ', appResourcesFullPath);
767746

768747
api.chainWebpack((config) => {
769748
config.entry('app').clear();
@@ -805,9 +784,7 @@ const webConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW) => {
805784
.loader('vue-loader')
806785
.options(
807786
Object.assign(
808-
{
809-
//compiler: NsVueTemplateCompiler,
810-
},
787+
{},
811788
config.module
812789
.rule('vue')
813790
.uses.get('vue-loader')
@@ -820,7 +797,6 @@ const webConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW) => {
820797
.rule('images')
821798
.uses.get('url-loader')
822799
.get('options');
823-
//imageLoaderOptions.fallback.options.name = isNVW ? 'assets/[name].[ext]' : 'assets/[name][hash:8].[ext]';
824800
imageLoaderOptions.fallback.options.name = 'assets/[name][hash:8].[ext]';
825801
config.module.rules.delete('images');
826802

@@ -874,9 +850,7 @@ const webConfig = (api, projectOptions, env, jsOrTs, projectRoot, isNVW) => {
874850
{
875851
from: {
876852
glob: '**/*.+(jpg|png)'
877-
} //,
878-
//to: join(dist, 'assets/[name][hash:8].[ext]'),
879-
//ignore: ['assets']
853+
}
880854
},
881855
{
882856
from: {

0 commit comments

Comments
 (0)