Skip to content

Commit 22adda3

Browse files
authored
Merge pull request #142 from NativeScript/update_dependencies
updating package.json
2 parents ec6216e + 7f1e431 commit 22adda3

File tree

4 files changed

+296
-2
lines changed

4 files changed

+296
-2
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ bin/
4444
gen/
4545

4646
package-lock.json
47-
webpack.config.js
4847
e2e/reports
4948
test-results.xml
5049

app/app.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
"id": "org.nativescript.nativescriptsdkexamplesjs",
2424
"tns-android": {
2525
"version": "5.4.0"
26+
},
27+
"tns-ios": {
28+
"version": "5.4.2"
2629
}
2730
},
2831
"dependencies": {
2932
"nativescript-theme-core": "~1.0.4",
30-
"tns-core-modules": "^5.3.1"
33+
"tns-core-modules": "^5.4.3"
3134
},
3235
"devDependencies": {
3336
"eslint": "~5.9.0",

webpack.config.js

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
const { join, relative, resolve, sep } = require("path");
2+
3+
const webpack = require("webpack");
4+
const nsWebpack = require("nativescript-dev-webpack");
5+
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6+
const CleanWebpackPlugin = require("clean-webpack-plugin");
7+
const CopyWebpackPlugin = require("copy-webpack-plugin");
8+
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
9+
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
10+
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
11+
const hashSalt = Date.now().toString();
12+
13+
module.exports = env => {
14+
// Add your custom Activities, Services and other Android app components here.
15+
const appComponents = [
16+
"tns-core-modules/ui/frame",
17+
"tns-core-modules/ui/frame/activity",
18+
];
19+
20+
const platform = env && (env.android && "android" || env.ios && "ios");
21+
if (!platform) {
22+
throw new Error("You need to provide a target platform!");
23+
}
24+
25+
const platforms = ["ios", "android"];
26+
const projectRoot = __dirname;
27+
28+
// Default destination inside platforms/<platform>/...
29+
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
30+
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
31+
32+
const {
33+
// The 'appPath' and 'appResourcesPath' values are fetched from
34+
// the nsconfig.json configuration file
35+
// when bundling with `tns run android|ios --bundle`.
36+
appPath = "app",
37+
appResourcesPath = "app/App_Resources",
38+
39+
// You can provide the following flags when running 'tns run android|ios'
40+
snapshot, // --env.snapshot
41+
uglify, // --env.uglify
42+
report, // --env.report
43+
sourceMap, // --env.sourceMap
44+
hmr, // --env.hmr,
45+
unitTesting, // --env.unitTesting
46+
} = env;
47+
const externals = nsWebpack.getConvertedExternals(env.externals);
48+
49+
const appFullPath = resolve(projectRoot, appPath);
50+
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
51+
52+
const entryModule = nsWebpack.getEntryModule(appFullPath);
53+
const entryPath = `.${sep}${entryModule}.ts`;
54+
const entries = { bundle: entryPath };
55+
if (platform === "ios") {
56+
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
57+
};
58+
59+
const config = {
60+
mode: uglify ? "production" : "development",
61+
context: appFullPath,
62+
externals,
63+
watchOptions: {
64+
ignored: [
65+
appResourcesFullPath,
66+
// Don't watch hidden files
67+
"**/.*",
68+
]
69+
},
70+
target: nativescriptTarget,
71+
entry: entries,
72+
output: {
73+
pathinfo: false,
74+
path: dist,
75+
libraryTarget: "commonjs2",
76+
filename: "[name].js",
77+
globalObject: "global",
78+
hashSalt
79+
},
80+
resolve: {
81+
extensions: [".ts", ".js", ".scss", ".css"],
82+
// Resolve {N} system modules from tns-core-modules
83+
modules: [
84+
resolve(__dirname, "node_modules/tns-core-modules"),
85+
resolve(__dirname, "node_modules"),
86+
"node_modules/tns-core-modules",
87+
"node_modules",
88+
],
89+
alias: {
90+
'~': appFullPath
91+
},
92+
// resolve symlinks to symlinked modules
93+
symlinks: true
94+
},
95+
resolveLoader: {
96+
// don't resolve symlinks to symlinked loaders
97+
symlinks: false
98+
},
99+
node: {
100+
// Disable node shims that conflict with NativeScript
101+
"http": false,
102+
"timers": false,
103+
"setImmediate": false,
104+
"fs": "empty",
105+
"__dirname": false,
106+
},
107+
devtool: sourceMap ? "inline-source-map" : "none",
108+
optimization: {
109+
runtimeChunk: "single",
110+
splitChunks: {
111+
cacheGroups: {
112+
vendor: {
113+
name: "vendor",
114+
chunks: "all",
115+
test: (module, chunks) => {
116+
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
117+
return /[\\/]node_modules[\\/]/.test(moduleName) ||
118+
appComponents.some(comp => comp === moduleName);
119+
120+
},
121+
enforce: true,
122+
},
123+
}
124+
},
125+
minimize: !!uglify,
126+
minimizer: [
127+
new UglifyJsPlugin({
128+
parallel: true,
129+
cache: true,
130+
uglifyOptions: {
131+
output: {
132+
comments: false,
133+
},
134+
compress: {
135+
// The Android SBG has problems parsing the output
136+
// when these options are enabled
137+
'collapse_vars': platform !== "android",
138+
sequences: platform !== "android",
139+
}
140+
}
141+
})
142+
],
143+
},
144+
module: {
145+
rules: [
146+
{
147+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
148+
use: [
149+
// Require all Android app components
150+
platform === "android" && {
151+
loader: "nativescript-dev-webpack/android-app-components-loader",
152+
options: { modules: appComponents }
153+
},
154+
155+
{
156+
loader: "nativescript-dev-webpack/bundle-config-loader",
157+
options: {
158+
loadCss: !snapshot, // load the application css if in debug mode
159+
unitTesting,
160+
appFullPath,
161+
projectRoot,
162+
}
163+
},
164+
].filter(loader => !!loader)
165+
},
166+
167+
{
168+
test: /-page\.ts$/,
169+
use: "nativescript-dev-webpack/script-hot-loader"
170+
},
171+
172+
{
173+
test: /\.(css|scss)$/,
174+
use: "nativescript-dev-webpack/style-hot-loader"
175+
},
176+
177+
{
178+
test: /\.(html|xml)$/,
179+
use: "nativescript-dev-webpack/markup-hot-loader"
180+
},
181+
182+
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },
183+
184+
{
185+
test: /\.css$/,
186+
use: { loader: "css-loader", options: { minimize: false, url: false } }
187+
},
188+
189+
{
190+
test: /\.scss$/,
191+
use: [
192+
{ loader: "css-loader", options: { minimize: false, url: false } },
193+
"sass-loader"
194+
]
195+
},
196+
197+
{
198+
test: /\.ts$/,
199+
use: {
200+
loader: "ts-loader",
201+
options: {
202+
configFile: "tsconfig.tns.json",
203+
allowTsInNodeModules: true,
204+
compilerOptions: {
205+
sourceMap
206+
}
207+
},
208+
}
209+
},
210+
]
211+
},
212+
plugins: [
213+
// Define useful constants like TNS_WEBPACK
214+
new webpack.DefinePlugin({
215+
"global.TNS_WEBPACK": "true",
216+
"process": undefined,
217+
}),
218+
// Remove all files from the out dir.
219+
new CleanWebpackPlugin([`${dist}/**/*`]),
220+
// Copy assets to out dir. Add your own globs as needed.
221+
new CopyWebpackPlugin([
222+
{ from: { glob: "ns-ui-widgets-category/web-view/source-load/*.html" } },
223+
{ from: { glob: "ns-ui-widgets-category/placeholder/platform-files/*.ts" } },
224+
{ from: { glob: "fonts/**" } },
225+
{ from: { glob: "**/*.jpg" } },
226+
{ from: { glob: "**/*.png" } },
227+
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
228+
// Generate a bundle starter script and activate it in package.json
229+
new nsWebpack.GenerateBundleStarterPlugin(
230+
// Don't include `runtime.js` when creating a snapshot. The plugin
231+
// configures the WebPack runtime to be generated inside the snapshot
232+
// module and no `runtime.js` module exist.
233+
(snapshot ? [] : ["./runtime"])
234+
.concat([
235+
"./vendor",
236+
"./bundle",
237+
])
238+
),
239+
// For instructions on how to set up workers with webpack
240+
// check out https://github.com/nativescript/worker-loader
241+
new NativeScriptWorkerPlugin(),
242+
new nsWebpack.PlatformFSPlugin({
243+
platform,
244+
platforms,
245+
}),
246+
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
247+
new nsWebpack.WatchStateLoggerPlugin(),
248+
],
249+
};
250+
251+
// Copy the native app resources to the out dir
252+
// only if doing a full build (tns run/build) and not previewing (tns preview)
253+
if (!externals || externals.length === 0) {
254+
config.plugins.push(new CopyWebpackPlugin([
255+
{
256+
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
257+
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
258+
context: projectRoot
259+
},
260+
]));
261+
}
262+
263+
if (report) {
264+
// Generate report files for bundles content
265+
config.plugins.push(new BundleAnalyzerPlugin({
266+
analyzerMode: "static",
267+
openAnalyzer: false,
268+
generateStatsFile: true,
269+
reportFilename: resolve(projectRoot, "report", `report.html`),
270+
statsFilename: resolve(projectRoot, "report", `stats.json`),
271+
}));
272+
}
273+
274+
if (snapshot) {
275+
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
276+
chunk: "vendor",
277+
requireModules: [
278+
"tns-core-modules/bundle-entry-points",
279+
],
280+
projectRoot,
281+
webpackConfig: config,
282+
}));
283+
}
284+
285+
if (hmr) {
286+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
287+
}
288+
289+
290+
return config;
291+
};

0 commit comments

Comments
 (0)