Skip to content

Commit 818e8ca

Browse files
committed
fix #47
1 parent 30f7ac9 commit 818e8ca

File tree

12 files changed

+3924
-3219
lines changed

12 files changed

+3924
-3219
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2016-2018 Tangra Inc.
189+
Copyright 2016-2019 Tangra Inc.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

demo/app/vendor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ application.loadAppCss();
77

88
require("./vendor-platform");
99

10-
require("nativescript-grid-view"); // Added for snapshots
11-
1210
require("bundle-entry-points");

demo/package-lock.json

Lines changed: 3094 additions & 2319 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"nativescript": {
33
"id": "com.tangrainc.gridviewsample",
44
"tns-android": {
5-
"version": "4.0.1"
5+
"version": "5.1.0"
66
},
77
"tns-ios": {
8-
"version": "4.0.1"
8+
"version": "5.1.0"
99
}
1010
},
1111
"scripts": {
@@ -14,29 +14,17 @@
1414
},
1515
"dependencies": {
1616
"nativescript-grid-view": "file:../bin/dist",
17-
"tns-core-modules": "~4.0.1"
17+
"tns-core-modules": "^5.1.1"
1818
},
1919
"devDependencies": {
20-
"awesome-typescript-loader": "~3.1.3",
2120
"babel-traverse": "6.26.0",
2221
"babel-types": "6.26.0",
2322
"babylon": "6.18.0",
24-
"clean-webpack-plugin": "~0.1.19",
25-
"copy-webpack-plugin": "~4.3.0",
26-
"css-loader": "~0.28.7",
27-
"extract-text-webpack-plugin": "~3.0.2",
2823
"lazy": "1.0.11",
2924
"nativescript-css-loader": "~0.26.0",
30-
"nativescript-dev-typescript": "^0.7.1",
31-
"nativescript-dev-webpack": "^0.11.0",
32-
"nativescript-worker-loader": "~0.8.1",
33-
"raw-loader": "~0.5.1",
34-
"resolve-url-loader": "~2.2.1",
35-
"tns-platform-declarations": "^3.4.0",
36-
"typescript": "~2.2.1",
37-
"uglifyjs-webpack-plugin": "~1.1.6",
38-
"webpack": "~3.10.0",
39-
"webpack-bundle-analyzer": "^2.9.1",
40-
"webpack-sources": "~1.1.0"
25+
"nativescript-dev-typescript": "^0.7.8",
26+
"nativescript-dev-webpack": "^0.19.0",
27+
"tns-platform-declarations": "^5.1.1",
28+
"typescript": "~3.1.6"
4129
}
4230
}

demo/tsconfig.tns.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"module": "es2015",
5+
"moduleResolution": "node"
6+
}
7+
}

demo/webpack.config.js

Lines changed: 126 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { relative, resolve, join } = require("path");
1+
const { join, relative, resolve, sep } = require("path");
22

33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
@@ -10,14 +10,19 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS
1010
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
1111

1212
module.exports = env => {
13+
// Add your custom Activities, Services and other Android app components here.
14+
const appComponents = [
15+
"tns-core-modules/ui/frame",
16+
"tns-core-modules/ui/frame/activity",
17+
];
18+
1319
const platform = env && (env.android && "android" || env.ios && "ios");
1420
if (!platform) {
1521
throw new Error("You need to provide a target platform!");
1622
}
1723

1824
const platforms = ["ios", "android"];
1925
const projectRoot = __dirname;
20-
nsWebpack.loadAdditionalPlugins({ projectDir: projectRoot });
2126

2227
// Default destination inside platforms/<platform>/...
2328
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
@@ -30,19 +35,27 @@ module.exports = env => {
3035
appPath = "app",
3136
appResourcesPath = "app/App_Resources",
3237

33-
// Snapshot, uglify and report can be enabled by providing
34-
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
35-
// when running 'tns run android|ios'
36-
snapshot,
37-
uglify,
38-
report,
38+
// You can provide the following flags when running 'tns run android|ios'
39+
snapshot, // --env.snapshot
40+
uglify, // --env.uglify
41+
report, // --env.report
42+
sourceMap, // --env.sourceMap
43+
hmr, // --env.hmr,
3944
} = env;
45+
const externals = (env.externals || []).map((e) => { // --env.externals
46+
return new RegExp(e + ".*");
47+
});
4048

4149
const appFullPath = resolve(projectRoot, appPath);
4250
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
4351

52+
const entryModule = nsWebpack.getEntryModule(appFullPath);
53+
const entryPath = `.${sep}${entryModule}.ts`;
54+
4455
const config = {
56+
mode: uglify ? "production" : "development",
4557
context: appFullPath,
58+
externals,
4659
watchOptions: {
4760
ignored: [
4861
appResourcesFullPath,
@@ -52,27 +65,29 @@ module.exports = env => {
5265
},
5366
target: nativescriptTarget,
5467
entry: {
55-
bundle: `./${nsWebpack.getEntryModule(appFullPath)}`,
56-
vendor: "./vendor"
68+
bundle: entryPath,
5769
},
5870
output: {
59-
pathinfo: true,
71+
pathinfo: false,
6072
path: dist,
6173
libraryTarget: "commonjs2",
6274
filename: "[name].js",
75+
globalObject: "global",
6376
},
6477
resolve: {
6578
extensions: [".ts", ".js", ".scss", ".css"],
6679
// Resolve {N} system modules from tns-core-modules
6780
modules: [
81+
resolve(__dirname, "node_modules/tns-core-modules"),
82+
resolve(__dirname, "node_modules"),
6883
"node_modules/tns-core-modules",
6984
"node_modules",
7085
],
7186
alias: {
72-
'~': resolve("./app")
87+
'~': appFullPath
7388
},
74-
// don't resolve symlinks to symlinked modules
75-
symlinks: false
89+
// resolve symlinks to symlinked modules
90+
symlinks: true
7691
},
7792
resolveLoader: {
7893
// don't resolve symlinks to symlinked loaders
@@ -84,10 +99,80 @@ module.exports = env => {
8499
"timers": false,
85100
"setImmediate": false,
86101
"fs": "empty",
102+
"__dirname": false,
103+
},
104+
devtool: sourceMap ? "inline-source-map" : "none",
105+
optimization: {
106+
splitChunks: {
107+
cacheGroups: {
108+
vendor: {
109+
name: "vendor",
110+
chunks: "all",
111+
test: (module, chunks) => {
112+
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
113+
return /[\\/]node_modules[\\/]/.test(moduleName) ||
114+
appComponents.some(comp => comp === moduleName);
115+
116+
},
117+
enforce: true,
118+
},
119+
}
120+
},
121+
minimize: !!uglify,
122+
minimizer: [
123+
new UglifyJsPlugin({
124+
parallel: true,
125+
cache: true,
126+
uglifyOptions: {
127+
output: {
128+
comments: false,
129+
},
130+
compress: {
131+
// The Android SBG has problems parsing the output
132+
// when these options are enabled
133+
'collapse_vars': platform !== "android",
134+
sequences: platform !== "android",
135+
}
136+
}
137+
})
138+
],
87139
},
88140
module: {
89141
rules: [
90-
{ test: /\.(html|xml)$/, use: "raw-loader" },
142+
{
143+
test: new RegExp(entryPath),
144+
use: [
145+
// Require all Android app components
146+
platform === "android" && {
147+
loader: "nativescript-dev-webpack/android-app-components-loader",
148+
options: { modules: appComponents }
149+
},
150+
151+
{
152+
loader: "nativescript-dev-webpack/bundle-config-loader",
153+
options: {
154+
loadCss: !snapshot, // load the application css if in debug mode
155+
}
156+
},
157+
].filter(loader => !!loader)
158+
},
159+
160+
{
161+
test: /-page\.ts$/,
162+
use: "nativescript-dev-webpack/script-hot-loader"
163+
},
164+
165+
{
166+
test: /\.(css|scss)$/,
167+
use: "nativescript-dev-webpack/style-hot-loader"
168+
},
169+
170+
{
171+
test: /\.(html|xml)$/,
172+
use: "nativescript-dev-webpack/markup-hot-loader"
173+
},
174+
175+
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"},
91176

92177
{
93178
test: /\.css$/,
@@ -102,17 +187,23 @@ module.exports = env => {
102187
]
103188
},
104189

105-
{ test: /\.ts$/, use: "awesome-typescript-loader" }
190+
{
191+
test: /\.ts$/,
192+
use: {
193+
loader: "ts-loader",
194+
options: {
195+
configFile: "tsconfig.tns.json",
196+
allowTsInNodeModules: true,
197+
},
198+
}
199+
},
106200
]
107201
},
108202
plugins: [
109-
// Vendor libs go to the vendor.js chunk
110-
new webpack.optimize.CommonsChunkPlugin({
111-
name: ["vendor"],
112-
}),
113203
// Define useful constants like TNS_WEBPACK
114204
new webpack.DefinePlugin({
115205
"global.TNS_WEBPACK": "true",
206+
"process": undefined,
116207
}),
117208
// Remove all files from the out dir.
118209
new CleanWebpackPlugin([ `${dist}/**/*` ]),
@@ -126,17 +217,17 @@ module.exports = env => {
126217
]),
127218
// Copy assets to out dir. Add your own globs as needed.
128219
new CopyWebpackPlugin([
129-
{ from: "fonts/**" },
130-
{ from: "**/*.jpg" },
131-
{ from: "**/*.png" },
132-
{ from: "**/*.xml" },
220+
{ from: { glob: "fonts/**" } },
221+
{ from: { glob: "**/*.jpg" } },
222+
{ from: { glob: "**/*.png" } },
133223
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
134224
// Generate a bundle starter script and activate it in package.json
135225
new nsWebpack.GenerateBundleStarterPlugin([
136226
"./vendor",
137227
"./bundle",
138228
]),
139-
// Support for web workers since v3.2
229+
// For instructions on how to set up workers with webpack
230+
// check out https://github.com/nativescript/worker-loader
140231
new NativeScriptWorkerPlugin(),
141232
new nsWebpack.PlatformFSPlugin({
142233
platform,
@@ -146,6 +237,7 @@ module.exports = env => {
146237
new nsWebpack.WatchStateLoggerPlugin(),
147238
],
148239
};
240+
149241
if (report) {
150242
// Generate report files for bundles content
151243
config.plugins.push(new BundleAnalyzerPlugin({
@@ -156,26 +248,22 @@ module.exports = env => {
156248
statsFilename: resolve(projectRoot, "report", `stats.json`),
157249
}));
158250
}
251+
159252
if (snapshot) {
160253
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
161254
chunk: "vendor",
255+
requireModules: [
256+
"tns-core-modules/bundle-entry-points",
257+
],
162258
projectRoot,
163259
webpackConfig: config,
164-
targetArchs: ["arm", "arm64", "ia32"],
165-
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
166-
useLibs: false
167260
}));
168261
}
169-
if (uglify) {
170-
config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
171-
172-
// Work around an Android issue by setting compress = false
173-
const compress = platform !== "android";
174-
config.plugins.push(new UglifyJsPlugin({
175-
uglifyOptions: {
176-
compress,
177-
}
178-
}));
262+
263+
if (hmr) {
264+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
179265
}
266+
267+
180268
return config;
181269
};

grid-view-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*! *****************************************************************************
2-
Copyright (c) 2018 Tangra Inc.
2+
Copyright (c) 2019 Tangra Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

grid-view.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*! *****************************************************************************
2-
Copyright (c) 2018 Tangra Inc.
2+
Copyright (c) 2019 Tangra Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

grid-view.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*! *****************************************************************************
2-
Copyright (c) 2018 Tangra Inc.
2+
Copyright (c) 2019 Tangra Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)