Skip to content

Commit 92edf54

Browse files
committed
added webpack to demo
1 parent edcbd66 commit 92edf54

File tree

12 files changed

+203
-5
lines changed

12 files changed

+203
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ obj
5353
node_modules
5454
*.tmp.*
5555
demo/platforms
56-
demo/lib
56+
demo/lib
57+
!webpack.*.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Forces the GridView to reload all its items.
103103
<!-- test-page.xml -->
104104
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:gv="nativescript-grid-view" loaded="pageLoaded">
105105
<GridLayout>
106-
<gv:GridView items="{{ items }}" colWidth="25%" rowHeight="15%" padding="5" itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
106+
<gv:GridView items="{{ items }}" colWidth="24%" rowHeight="15%" padding="5" itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
107107
<gv:GridView.itemTemplate>
108108
<GridLayout backgroundColor="#33ffff" style="margin: 5">
109109
<Label text="{{ value }}" verticalAlignment="center"/>

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-grid-view", () => require("nativescript-grid-view"));
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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,32 @@
1010
},
1111
"scripts": {
1212
"android": "npm uninstall nativescript-grid-view && tns platform remove android && tns platform add android@rc && tns run android --emulator",
13-
"ios": "npm uninstall nativescript-grid-view && tns run ios --emulator"
13+
"ios": "npm uninstall nativescript-grid-view && tns run ios --emulator",
14+
"ns-bundle": "ns-bundle",
15+
"start-android-bundle": "npm run ns-bundle --android --start-app --uglify",
16+
"start-ios-bundle": "npm run ns-bundle --ios --start-app --uglify",
17+
"build-android-bundle": "npm run ns-bundle --android --build-app",
18+
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
1419
},
1520
"dependencies": {
1621
"nativescript-grid-view": "file:../bin/dist",
1722
"tns-core-modules": "rc"
1823
},
1924
"devDependencies": {
25+
"awesome-typescript-loader": "~3.0.0-beta.9",
2026
"babel-traverse": "6.21.0",
2127
"babel-types": "6.21.0",
2228
"babylon": "6.14.1",
29+
"copy-webpack-plugin": "~3.0.1",
30+
"extract-text-webpack-plugin": "~2.0.0-beta.4",
2331
"lazy": "1.0.11",
32+
"nativescript-css-loader": "~0.26.0",
2433
"nativescript-dev-typescript": "0.4.2",
25-
"typescript": "2.2.2"
34+
"nativescript-dev-webpack": "^0.3.7",
35+
"raw-loader": "~0.5.1",
36+
"resolve-url-loader": "~1.6.0",
37+
"typescript": "2.2.2",
38+
"webpack": "2.2.0",
39+
"webpack-sources": "~0.1.3"
2640
}
2741
}

demo/webpack.android.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var makeConfig = require("./webpack.common");
2+
module.exports = makeConfig("android");

demo/webpack.common.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
var webpack = require("webpack");
2+
var nsWebpack = require("nativescript-dev-webpack");
3+
var nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
4+
var path = require("path");
5+
var CopyWebpackPlugin = require("copy-webpack-plugin");
6+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
7+
var gridViewMangleExcludes = require("nativescript-grid-view/uglify-mangle-excludes").default;
8+
9+
module.exports = function (platform, destinationApp) {
10+
if (!destinationApp) {
11+
//Default destination inside platforms/<platform>/...
12+
destinationApp = nsWebpack.getAppPath(platform);
13+
}
14+
var entry = {};
15+
//Discover entry module from package.json
16+
entry.bundle = "./" + nsWebpack.getEntryModule();
17+
//Vendor entry with third party libraries.
18+
entry.vendor = "./vendor";
19+
//app.css bundle
20+
entry["app.css"] = "./app.css";
21+
22+
var plugins = [
23+
new ExtractTextPlugin("app.css"),
24+
//Vendor libs go to the vendor.js chunk
25+
new webpack.optimize.CommonsChunkPlugin({
26+
name: ["vendor"]
27+
}),
28+
//Define useful constants like TNS_WEBPACK
29+
new webpack.DefinePlugin({
30+
"global.TNS_WEBPACK": "true",
31+
}),
32+
//Copy assets to out dir. Add your own globs as needed.
33+
new CopyWebpackPlugin([
34+
{ from: "app.css" },
35+
{ from: "css/**" },
36+
{ from: "fonts/**" },
37+
{ from: "**/*.jpg" },
38+
{ from: "**/*.png" },
39+
{ from: "**/*.xml" },
40+
], { ignore: ["App_Resources/**"] }),
41+
//Generate a bundle starter script and activate it in package.json
42+
new nsWebpack.GenerateBundleStarterPlugin([
43+
"./vendor",
44+
"./bundle",
45+
]),
46+
];
47+
48+
if (process.env.npm_config_uglify) {
49+
plugins.push(new webpack.LoaderOptionsPlugin({
50+
minimize: true
51+
}));
52+
53+
//Work around an Android issue by setting compress = false
54+
var compress = platform !== "android";
55+
plugins.push(new webpack.optimize.UglifyJsPlugin({
56+
mangle: {
57+
except: nsWebpack.uglifyMangleExcludes.concat(gridViewMangleExcludes),
58+
},
59+
compress: compress,
60+
}));
61+
}
62+
63+
return {
64+
context: path.resolve("./app"),
65+
target: nativescriptTarget,
66+
entry: entry,
67+
output: {
68+
pathinfo: true,
69+
path: path.resolve(destinationApp),
70+
libraryTarget: "commonjs2",
71+
filename: "[name].js",
72+
},
73+
resolve: {
74+
//Resolve platform-specific modules like module.android.js
75+
extensions: [
76+
".ts",
77+
".js",
78+
".css",
79+
"." + platform + ".ts",
80+
"." + platform + ".js",
81+
"." + platform + ".css",
82+
],
83+
//Resolve {N} system modules from tns-core-modules
84+
modules: [
85+
"node_modules/tns-core-modules",
86+
"node_modules"
87+
]
88+
},
89+
node: {
90+
//Disable node shims that conflict with NativeScript
91+
"http": false,
92+
"timers": false,
93+
"setImmediate": false,
94+
"fs": "empty",
95+
},
96+
module: {
97+
loaders: [
98+
{
99+
test: /\.html$/,
100+
loader: "raw-loader"
101+
},
102+
// Root app.css file gets extracted with bundled dependencies
103+
{
104+
test: /app\.css$/,
105+
loader: ExtractTextPlugin.extract([
106+
"resolve-url-loader",
107+
"nativescript-css-loader",
108+
"nativescript-dev-webpack/platform-css-loader",
109+
]),
110+
},
111+
// Other CSS files get bundled using the raw loader
112+
{
113+
test: /\.css$/,
114+
exclude: /app\.css$/,
115+
loaders: [
116+
"raw-loader",
117+
]
118+
},
119+
// Compile TypeScript files, replace templateUrl and styleUrls.
120+
{
121+
test: /\.ts$/,
122+
loaders: [
123+
"awesome-typescript-loader"
124+
]
125+
},
126+
// SASS support
127+
{
128+
test: /\.scss$/,
129+
loaders: [
130+
"raw-loader",
131+
"resolve-url-loader",
132+
"sass-loader"
133+
]
134+
},
135+
]
136+
},
137+
plugins: plugins,
138+
};
139+
};

0 commit comments

Comments
 (0)