Skip to content

Commit a3fab61

Browse files
HMR Working (#19)
* fix regex to detect current working directory at install * webpack config update * updated dependencies * got HMR working * removed forcing a webpack dev-dependecy install * manually adding PR#10 changes
1 parent 3fe55cd commit a3fab61

File tree

5 files changed

+1669
-1007
lines changed

5 files changed

+1669
-1007
lines changed

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ An example of this would be the following Vue component:
5353
```
5454

5555
### Optional Separation 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.
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`, `.css`, `.styl`, and `.less` files.
5757

5858
| File Type | Android __and__ IOS | Android only | IOS only | Web only |
5959
| ---------- | ------------------- | --------------- | --------------- | --------------- |
@@ -62,6 +62,8 @@ If you want complete seperation of concerns between Web and Native for component
6262
| ts | *.native.ts | *.android.ts | *.ios.ts | *.ts |
6363
| scss | *.native.scss | *.android.scss | *.ios.scss | *.scss |
6464
| css | *.native.css | *.android.css | *.ios.css | *.css |
65+
| stylus | *.native.styl | *.android.styl | *.ios.styl | *.styl |
66+
| less | *.native.less | *.android.less | *.ios.less | *.less |
6567

6668
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.
6769

@@ -204,10 +206,12 @@ You should be able to use the NativeScript Playground and Preview Apps via the f
204206
1. `npm run preview:android`
205207
2. `npm run preview:ios`
206208

207-
#### --env command line recognition
209+
#### --env & --hmr command line recognition
208210
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.
209211
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.
210212

213+
HMR will also work by passing in `-- --hmr`. An example of this would be `npm run serve:android -- --hmr`
214+
211215
#### Webpack related information
212216
The options passed 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`.
213217

Diff for: generator/index.js

+60-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-console */
2+
23
const path = require('path');
34
const fs = require('fs-extra');
45
const replace = require('replace-in-file');
@@ -53,10 +54,10 @@ module.exports = async (api, options, rootOptions) => {
5354
nativescript: {
5455
id: 'org.nativescript.application',
5556
'tns-ios': {
56-
version: '5.2.0'
57+
version: '5.4.0'
5758
},
5859
'tns-android': {
59-
version: '5.2.1'
60+
version: '5.4.0'
6061
}
6162
},
6263
scripts: {
@@ -77,18 +78,18 @@ module.exports = async (api, options, rootOptions) => {
7778
'clean:ios': 'rimraf platforms/ios'
7879
},
7980
dependencies: {
80-
'nativescript-vue': '^2.2.0',
81-
'tns-core-modules': '^5.2.2'
81+
'nativescript-vue': '^2.2.2',
82+
'tns-core-modules': '^5.4.1'
8283
},
8384
devDependencies: {
84-
'nativescript-dev-webpack': '^0.20.3',
85-
'nativescript-vue-template-compiler': '^2.2.0',
85+
'nativescript-dev-webpack': '^0.22.0',
86+
'nativescript-vue-template-compiler': '^2.2.2',
8687
'nativescript-worker-loader': '~0.9.5',
8788
'node-sass': '^4.11.0',
8889
'string-replace-loader': '^2.1.1',
89-
rimraf: '^2.6.3',
90-
webpack: '^4.29.6',
91-
'webpack-cli': '^3.3.0'
90+
rimraf: '^2.6.3'
91+
// webpack: '4.28.4',
92+
// 'webpack-cli': '^3.3.2'
9293
}
9394
});
9495

@@ -126,8 +127,8 @@ module.exports = async (api, options, rootOptions) => {
126127
api.extendPackage({
127128
dependencies: {},
128129
devDependencies: {
129-
'fork-ts-checker-webpack-plugin': '^1.0.0',
130-
'terser-webpack-plugin': '^1.2.3'
130+
'fork-ts-checker-webpack-plugin': '^1.3.4',
131+
'terser-webpack-plugin': '^1.3.0'
131132
//'tns-platform-declarations': '^4.2.1'
132133
}
133134
});
@@ -137,7 +138,7 @@ module.exports = async (api, options, rootOptions) => {
137138
api.extendPackage({
138139
dependencies: {},
139140
devDependencies: {
140-
'@babel/types': '^7.4.0'
141+
'@babel/types': '^7.4.4'
141142
}
142143
});
143144
}
@@ -147,10 +148,10 @@ module.exports = async (api, options, rootOptions) => {
147148
if (api.hasPlugin('babel')) {
148149
api.extendPackage({
149150
devDependencies: {
150-
'@babel/core': '^7.4.0',
151-
'@babel/preset-env': '^7.4.1',
152-
'babel-loader': '^8.0.5',
153-
'@babel/traverse': '^7.4.0'
151+
'@babel/core': '^7.4.5',
152+
'@babel/preset-env': '^7.4.5',
153+
'babel-loader': '^8.0.6',
154+
'@babel/traverse': '^7.4.5'
154155
}
155156
});
156157

@@ -277,9 +278,13 @@ module.exports = async (api, options, rootOptions) => {
277278
await tslintSetup(genConfig.dirPathPrefix, api.resolve('tslint.json'), genConfig.tsExclusionArray);
278279

279280
const baseDir = genConfig.nativeAppPathModifier;
280-
require('../lib/tslint')({
281-
'_': [`${baseDir}**/*.ts`, `${baseDir}**/*.vue`, `${baseDir}**/*.tsx`, 'tests/**/*.ts', 'tests/**/*.tsx']
282-
}, api, false);
281+
require('../lib/tslint')(
282+
{
283+
_: [`${baseDir}**/*.ts`, `${baseDir}**/*.vue`, `${baseDir}**/*.tsx`, 'tests/**/*.ts', 'tests/**/*.tsx']
284+
},
285+
api,
286+
false
287+
);
283288
}
284289
}
285290

@@ -844,8 +849,7 @@ const renderDirectoryStructure = (module.exports.renderDirectoryStructure = asyn
844849
) => {
845850
try {
846851
const files = new Array();
847-
const baseDir = await extractCallDir();
848-
const _files = await getAllFilesInDirStructure(srcPathPrefix, baseDir);
852+
const _files = await getAllFilesInDirStructure(srcPathPrefix, __dirname);
849853

850854
for (const rawPath of _files) {
851855
// // // let filename = path.basename(rawPath);
@@ -899,22 +903,41 @@ const renderDirectoryStructure = (module.exports.renderDirectoryStructure = asyn
899903
}
900904
});
901905

902-
// extract callsite file location using error stack
903-
const extractCallDir = (module.exports.extractCallDir = () => {
904-
try {
905-
const obj = {};
906-
Error.captureStackTrace(obj);
907-
const callSite = obj.stack.split('\n')[3];
908-
let { fileName } = /(?<fileName>[^(\s]+):[0-9]+:[0-9]+/.exec(callSite).groups;
909-
if (fileName.indexOf('file') >= 0) {
910-
fileName = new URL(fileName).pathname;
911-
}
912-
let dirname = path.dirname(fileName);
913-
return dirname;
914-
} catch (err) {
915-
throw err;
916-
}
917-
});
906+
// THIS FUNCTION MAY NOT LONGER BE NEEDED AS OF 0.0.16
907+
// WILL KEEP THIS COMMENTED OUT CODE IN FOR A FEW OF RELEASES
908+
// // extract callsite file location using error stack
909+
// const extractCallDir = (module.exports.extractCallDir = () => {
910+
// try {
911+
// const obj = {};
912+
// console.log('__dirname - ', __dirname);
913+
// Error.captureStackTrace(obj);
914+
// const callSite = obj.stack.split('\n')[3];
915+
// console.log('callSite - ', callSite);
916+
917+
// let { fileName } = /(?<fileName>[^(]+):[0-9]+:[0-9]+/.exec(callSite).groups;
918+
// console.log('fileName 1 - ', fileName);
919+
920+
// if (fileName.indexOf('file') >= 0) {
921+
// fileName = new URL(fileName).pathname;
922+
// }
923+
924+
// if (fileName.indexOf(fileName.length - 1) === ')') {
925+
// fileName = fileName.splice(0, fileName.length - 1);
926+
// }
927+
928+
// console.log(`fileName 2 - '`, fileName + `'`);
929+
930+
// fileName = fileName.replace('at ', '');
931+
// console.log(`fileName 3 - '`, fileName) + `'`;
932+
933+
// let dirname = path.dirname(fileName);
934+
// console.log(`dirname - '`, dirname + `'`);
935+
936+
// return __dirname;
937+
// } catch (err) {
938+
// throw err;
939+
// }
940+
// });
918941

919942
// utility function used to get all the files in a directory structure. is recursive in nature due to globby
920943
const getAllFilesInDirStructure = (module.exports.replaceInFile = async (srcPathPrefix, baseDir) => {

0 commit comments

Comments
 (0)