Skip to content

Commit 130f3bc

Browse files
add DEBUG_MODE env variable
Signed-off-by: Arnav Gupta <arnav@codingblocks.com>
1 parent 69e5dd2 commit 130f3bc

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# JetBrains project files
22
.idea
33

4+
# VS Code
5+
.vscode
6+
47
# NPM
58
node_modules
69

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,33 @@ https://typescriptlang.org
3333

3434
## Usage
3535

36+
### Installing and Running
37+
Here `<platform>` can be `android` or `ios`
38+
3639
``` bash
3740
# Install dependencies
3841
npm install
3942

40-
# Build for production
41-
tns build <platform> --bundle
43+
# Build, watch for changes and run the application
44+
tns run <platform> --bundle
45+
```
46+
47+
### Debugging vs Production
48+
49+
During usual run, project runs with following settings -
50+
1. Code is **not** minified
51+
2. Vue.config.silent is false, so every component creation is logged
4252

53+
```bash
4354
# Build, watch for changes and debug the application
4455
tns debug <platform> --bundle
56+
```
4557

46-
# Build, watch for changes and run the application
47-
tns run <platform> --bundle
58+
To minify code, and prevent Vue logs -
59+
60+
```bash
61+
# Build for production
62+
tns build <platform> --bundle --env.production
63+
64+
tns run <platform> --bundle --env.production
4865
```

app/App_Resources/Android/app.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android {
44
defaultConfig {
55
generatedDensities = []
6-
applicationId = "__PACKAGE__"
6+
applicationId = "in.championswimmer.nsvuets"
77
}
88
aaptOptions {
99
additionalParameters "--no-version-vectors"

app/main.js renamed to app/main.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import Vue from 'nativescript-vue';
2-
32
import router from './router';
4-
53
import store from './store';
6-
74
import './styles.scss';
85

9-
// Uncomment the following to see NativeScript-Vue output logs
10-
//Vue.config.silent = false;
6+
// See NativeScript-Vue output logs in debug
7+
Vue.config.silent = !DEBUG_MODE
118

129
new Vue({
1310

app/store/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import counter from './modules/counter';
55

66
Vue.use(Vuex);
77

8-
declare var process: {env: {[s: string]: string}};
9-
const debug = process.env.NODE_ENV !== 'production';
10-
118
const store = new Vuex.Store({
129
modules: {
1310
counter,
1411
},
15-
strict: debug,
12+
strict: DEBUG_MODE,
1613
});
1714

1815
Vue.prototype.$store = store;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
"webpack-bundle-analyzer": "~2.13.1",
4646
"webpack-cli": "^3.1.0"
4747
}
48-
}
48+
}

types/nativescript-vue.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var DEBUG_MODE: boolean

webpack.config.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ module.exports = env => {
3838
// the nsconfig.json configuration file
3939
// when bundling with `tns run android|ios --bundle`.
4040
appPath = "app",
41-
appResourcesPath = "app/App_Resources",
41+
appResourcesPath = "app/App_Resources",
4242

43-
// You can provide the following flags when running 'tns run android|ios'
44-
snapshot, // --env.snapshot
45-
uglify, // --env.uglify
46-
report, // --env.report
43+
// You can provide the following flags when running 'tns run android|ios'
44+
snapshot, // --env.snapshot
45+
production, // --env.production
46+
report, // --env.report
4747
} = env;
4848

4949
const appFullPath = resolve(projectRoot, appPath);
5050
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
5151

5252
const entryModule = nsWebpack.getEntryModule(appFullPath);
53-
const entryPath = `.${sep}${entryModule}.js`;
53+
const entryPath = `.${sep}${entryModule}.ts`;
5454
console.log(`Bundling application for entryPath ${entryPath}...`);
5555

5656
const config = {
57-
mode: uglify ? "production" : "development",
57+
mode: production ? "production" : "development",
5858
context: appFullPath,
5959
watchOptions: {
6060
ignored: [
@@ -120,7 +120,7 @@ module.exports = env => {
120120
},
121121
},
122122
},
123-
minimize: Boolean(uglify),
123+
minimize: Boolean(production),
124124
minimizer: [
125125
new UglifyJsPlugin({
126126
uglifyOptions: {
@@ -200,6 +200,7 @@ module.exports = env => {
200200
// Define useful constants like TNS_WEBPACK
201201
new webpack.DefinePlugin({
202202
"global.TNS_WEBPACK": "true",
203+
"DEBUG_MODE": !production
203204
}),
204205
// Remove all files from the out dir.
205206
new CleanWebpackPlugin([`${dist}/**/*`]),

0 commit comments

Comments
 (0)