Skip to content

Commit 2f4ddc4

Browse files
committed
added webpack
1 parent 7674098 commit 2f4ddc4

15 files changed

+244
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ node_modules
5555
platforms
5656
demo/lib
5757
*.log
58+
!webpack.*.js

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"**/.git": true,
55
"**/.DS_Store": true,
66
"demo": true,
7+
"demo-ng": true,
78
"bin/**": true
89
}
910
}

.vscode/tasks.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212
"args": [],
1313
"isBuildCommand": true,
1414
"problemMatcher": ["$tsc", {
15-
"owner": "tslint",
16-
"fileLocation": [
17-
"relative",
18-
"${workspaceRoot}"
19-
],
20-
"severity": "warning",
21-
"pattern": "$tslint4"
15+
"base": "$tslint4",
16+
"fileLocation": "relative"
2217
}]
2318
}
2419
]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,28 @@ dd.selectedIndex = itemSource.getIndex("FL");
209209
```TypeScript
210210
let selectedValue = itemSource.getValue(dd.selectedIndex);
211211
```
212+
213+
## Working with Webpack+Uglify
214+
In case you are uing webpack and also are minifying/uglifying your code, there are some specific names that should be excluded from the uglification for the widget to work properly. The DropDown widget export those and you need to add them to the mangle exclude option of the uglifyjs plugin in the `webpack.common.js` file:
215+
```js
216+
var dropDownMangleExcludes = require("nativescript-drop-down/uglify-mangle-excludes").default;
217+
//......
218+
module.exports = function (platform, destinationApp) {
219+
//......
220+
if (process.env.npm_config_uglify) {
221+
plugins.push(new webpack.LoaderOptionsPlugin({
222+
minimize: true
223+
}));
224+
225+
//Work around an Android issue by setting compress = false
226+
var compress = platform !== "android";
227+
plugins.push(new webpack.optimize.UglifyJsPlugin({
228+
mangle: {
229+
except: nsWebpack.uglifyMangleExcludes.concat(dropDownMangleExcludes),
230+
},
231+
compress: compress,
232+
}));
233+
}
234+
//......
235+
}
236+
```

demo/app/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "./bundle-config";
2+
13
import application = require("application");
24

35
application.start({ moduleName: "main-page" });

demo/app/bundle-config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if ((global as any).TNS_WEBPACK) {
2+
// registers tns-core-modules UI framework modules
3+
// tslint:disable-next-line:no-var-requires
4+
require("bundle-entry-points");
5+
6+
global.registerModule("nativescript-drop-down", () => require("nativescript-drop-down"));
7+
8+
// Views
9+
global.registerModule("main-page", () => require("./main-page"));
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Resolve JavaScript classes that extend a Java class, and need to resolve
2+
// their JavaScript module from a bundled script. For example:
3+
// NativeScriptApplication, NativeScriptActivity, etc.
4+
//
5+
// This module gets bundled together with the rest of the app code and the
6+
// `require` calls get resolved to the correct bundling import call.
7+
//
8+
// At runtime the module gets loaded *before* the rest of the app code, so code
9+
// placed here needs to be careful about its dependencies.
10+
11+
require("application");
12+
require("ui/frame");
13+
require("ui/frame/activity");
14+
15+
if (global.TNS_WEBPACK) {
16+
global.__requireOverride = function (name, dir) {
17+
if (name === "./tns_modules/application/application.js") {
18+
return require("application");
19+
} else if (name === "./tns_modules/ui/frame/frame.js") {
20+
return require("ui/frame");
21+
} else if (name === "./tns_modules/ui/frame/activity.js") {
22+
return require("ui/frame/activity");
23+
}
24+
};
25+
}

demo/app/vendor-platform.ios.ts

Whitespace-only changes.

demo/app/vendor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require("./vendor-platform");
2+
3+
require("bundle-entry-points");

demo/package.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
{
22
"nativescript": {
33
"id": "com.tangrainc.dropdownsample",
4-
"tns-ios": {
4+
"tns-android": {
55
"version": "3.0.0-rc.1"
66
},
7-
"tns-android": {
7+
"tns-ios": {
88
"version": "3.0.0-rc.1"
99
}
1010
},
1111
"scripts": {
1212
"android": "npm uninstall nativescript-drop-down && tns platform remove android && tns platform add android@rc && tns run android",
1313
"ios": "npm uninstall nativescript-drop-down && tns run ios --emulator",
14-
"debug-ios": "npm uninstall nativescript-drop-down && tns debug ios --emulator"
14+
"debug-ios": "npm uninstall nativescript-drop-down && tns debug ios --emulator",
15+
"ns-bundle": "ns-bundle",
16+
"start-android-bundle": "npm run ns-bundle --android --start-app",
17+
"start-ios-bundle": "npm run ns-bundle --ios --start-app --uglify",
18+
"build-android-bundle": "npm run ns-bundle --android --build-app",
19+
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
1520
},
1621
"dependencies": {
1722
"nativescript-drop-down": "file:../bin/dist",
1823
"tns-core-modules": "rc"
1924
},
2025
"devDependencies": {
26+
"awesome-typescript-loader": "~3.0.0-beta.9",
2127
"babel-traverse": "6.10.4",
2228
"babel-types": "6.11.1",
2329
"babylon": "6.8.2",
30+
"copy-webpack-plugin": "~3.0.1",
31+
"extract-text-webpack-plugin": "~2.0.0-beta.4",
2432
"filewalker": "0.1.3",
2533
"lazy": "1.0.11",
34+
"nativescript-css-loader": "~0.26.0",
2635
"nativescript-dev-typescript": "^0.4.0",
36+
"nativescript-dev-webpack": "^0.3.7",
37+
"raw-loader": "~0.5.1",
38+
"resolve-url-loader": "~1.6.0",
39+
"tns-platform-declarations": "rc",
2740
"typescript": "^2.2.2",
28-
"tns-platform-declarations": "rc"
41+
"webpack": "2.2.0",
42+
"webpack-sources": "~0.1.3"
2943
}
3044
}

0 commit comments

Comments
 (0)