Skip to content

Commit 66d496e

Browse files
committed
chore: update webpack deps
1 parent ae923d3 commit 66d496e

File tree

4 files changed

+210
-20
lines changed

4 files changed

+210
-20
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"lazy": "1.0.11",
4040
"nativescript-css-loader": "~0.26.0",
4141
"nativescript-dev-typescript": "~0.4.2",
42-
"nativescript-dev-webpack": "^0.4.1",
42+
"nativescript-dev-webpack": "^0.5.0",
4343
"raw-loader": "~0.5.1",
4444
"resolve-url-loader": "~2.0.2",
4545
"typescript": "~2.3.2",
46-
"webpack": "~2.4.1",
46+
"webpack": "~2.5.1",
4747
"webpack-sources": "~0.2.3"
4848
},
4949
"scripts": {

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"platforms",
2525
"**/*.aot.ts"
2626
]
27-
}
27+
}

Diff for: webpack.config.js

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
const { resolve, join } = 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 CopyWebpackPlugin = require("copy-webpack-plugin");
7+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
8+
9+
const { AotPlugin } = require("@ngtools/webpack");
10+
11+
const mainSheet = `app.css`;
12+
13+
module.exports = env => {
14+
const platform = getPlatform(env);
15+
16+
// Default destination inside platforms/<platform>/...
17+
const path = resolve(nsWebpack.getAppPath(platform));
18+
19+
const entry = {
20+
// Discover entry module from package.json
21+
bundle: `./${nsWebpack.getEntryModule()}`,
22+
23+
// Vendor entry with third-party libraries
24+
vendor: `./vendor`,
25+
26+
// Entry for stylesheet with global application styles
27+
[mainSheet]: `./${mainSheet}`,
28+
};
29+
30+
const rules = getRules();
31+
const plugins = getPlugins(platform, env);
32+
const extensions = getExtensions(platform);
33+
34+
return {
35+
context: resolve("./app"),
36+
target: nativescriptTarget,
37+
entry,
38+
output: {
39+
pathinfo: true,
40+
path,
41+
libraryTarget: "commonjs2",
42+
filename: "[name].js",
43+
},
44+
resolve: {
45+
extensions,
46+
47+
// Resolve {N} system modules from tns-core-modules
48+
modules: [
49+
"node_modules/tns-core-modules",
50+
"node_modules",
51+
]
52+
},
53+
node: {
54+
// Disable node shims that conflict with NativeScript
55+
"http": false,
56+
"timers": false,
57+
"setImmediate": false,
58+
"fs": "empty",
59+
},
60+
module: { rules },
61+
plugins,
62+
};
63+
};
64+
65+
66+
function getPlatform(env) {
67+
return env.android ? "android" :
68+
env.ios ? "ios" :
69+
() => { throw new Error("You need to provide a target platform!") };
70+
}
71+
72+
function getRules() {
73+
return [
74+
{
75+
test: /\.html$|\.xml$/,
76+
use: [
77+
"raw-loader",
78+
]
79+
},
80+
// Root stylesheet gets extracted with bundled dependencies
81+
{
82+
test: new RegExp(mainSheet),
83+
use: ExtractTextPlugin.extract([
84+
{
85+
loader: "resolve-url-loader",
86+
options: { silent: true },
87+
},
88+
"nativescript-css-loader",
89+
"nativescript-dev-webpack/platform-css-loader",
90+
]),
91+
},
92+
// Other CSS files get bundled using the raw loader
93+
{
94+
test: /\.css$/,
95+
exclude: new RegExp(mainSheet),
96+
use: [
97+
"raw-loader",
98+
]
99+
},
100+
// SASS support
101+
{
102+
test: /\.scss$/,
103+
use: [
104+
"raw-loader",
105+
"resolve-url-loader",
106+
"sass-loader",
107+
]
108+
},
109+
110+
111+
// Compile TypeScript files with ahead-of-time compiler.
112+
{
113+
test: /\.ts$/,
114+
loaders: [
115+
"nativescript-dev-webpack/tns-aot-loader",
116+
"@ngtools/webpack",
117+
]
118+
}
119+
120+
];
121+
}
122+
123+
function getPlugins(platform, env) {
124+
let plugins = [
125+
new ExtractTextPlugin(mainSheet),
126+
127+
// Vendor libs go to the vendor.js chunk
128+
new webpack.optimize.CommonsChunkPlugin({
129+
name: ["vendor"],
130+
}),
131+
132+
// Define useful constants like TNS_WEBPACK
133+
new webpack.DefinePlugin({
134+
"global.TNS_WEBPACK": "true",
135+
}),
136+
137+
// Copy assets to out dir. Add your own globs as needed.
138+
new CopyWebpackPlugin([
139+
{ from: mainSheet },
140+
{ from: "css/**" },
141+
{ from: "fonts/**" },
142+
{ from: "**/*.jpg" },
143+
{ from: "**/*.png" },
144+
{ from: "**/*.xml" },
145+
], { ignore: ["App_Resources/**"] }),
146+
147+
// Generate a bundle starter script and activate it in package.json
148+
new nsWebpack.GenerateBundleStarterPlugin([
149+
"./vendor",
150+
"./bundle",
151+
]),
152+
153+
// Angular AOT compiler
154+
new AotPlugin({
155+
tsConfigPath: "tsconfig.aot.json",
156+
entryModule: resolve(__dirname, "app/app.module#AppModule"),
157+
typeChecking: false
158+
}),
159+
160+
// Resolve .ios.css and .android.css component stylesheets
161+
new nsWebpack.StyleUrlResolvePlugin({platform}),
162+
163+
];
164+
165+
if (env.uglify) {
166+
plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
167+
168+
// Work around an Android issue by setting compress = false
169+
const compress = platform !== "android";
170+
plugins.push(new webpack.optimize.UglifyJsPlugin({
171+
mangle: { except: nsWebpack.uglifyMangleExcludes },
172+
compress,
173+
}));
174+
}
175+
176+
return plugins;
177+
}
178+
179+
// Resolve platform-specific modules like module.android.js
180+
function getExtensions(platform) {
181+
return Object.freeze([
182+
`.${platform}.ts`,
183+
`.${platform}.js`,
184+
".aot.ts",
185+
".ts",
186+
".js",
187+
".css",
188+
`.${platform}.css`,
189+
]);
190+
}

Diff for: yarn.lock

+17-17
Original file line numberDiff line numberDiff line change
@@ -1614,9 +1614,9 @@ nan@^2.3.0:
16141614
version "2.6.2"
16151615
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
16161616

1617-
nativescript-angular@~3.0.0:
1618-
version "3.0.0"
1619-
resolved "https://registry.yarnpkg.com/nativescript-angular/-/nativescript-angular-3.0.0.tgz#401c5eae895c22a44010c16f443910d2aa5af6ee"
1617+
nativescript-angular@next:
1618+
version "3.1.0-2017-05-10-1537"
1619+
resolved "https://registry.yarnpkg.com/nativescript-angular/-/nativescript-angular-3.1.0-2017-05-10-1537.tgz#ca40b1fbb2f5029960184db686b09815f40b24fb"
16201620
dependencies:
16211621
nativescript-intl "^3.0.0"
16221622
reflect-metadata "^0.1.8"
@@ -1644,9 +1644,9 @@ nativescript-dev-typescript@~0.4.2:
16441644
dependencies:
16451645
nativescript-hook "^0.2.0"
16461646

1647-
nativescript-dev-webpack@^0.4.1:
1648-
version "0.4.1"
1649-
resolved "https://registry.yarnpkg.com/nativescript-dev-webpack/-/nativescript-dev-webpack-0.4.1.tgz#be1a96a866be21d245c1d7d8b2a3c23c4f08936f"
1647+
nativescript-dev-webpack@^0.5.0:
1648+
version "0.5.0"
1649+
resolved "https://registry.yarnpkg.com/nativescript-dev-webpack/-/nativescript-dev-webpack-0.5.0.tgz#b439853be73f0776ff1b60b883dee4afbda551cd"
16501650

16511651
nativescript-hook@^0.2.0:
16521652
version "0.2.1"
@@ -2628,15 +2628,15 @@ timers-browserify@^2.0.2:
26282628
dependencies:
26292629
setimmediate "^1.0.4"
26302630

2631-
tns-core-modules-widgets@3.0.0:
2632-
version "3.0.0"
2633-
resolved "https://registry.yarnpkg.com/tns-core-modules-widgets/-/tns-core-modules-widgets-3.0.0.tgz#503c762819c936ce51e0b6025c776ae42a4500fb"
2631+
tns-core-modules-widgets@next:
2632+
version "3.1.0-2017-05-17-291"
2633+
resolved "https://registry.yarnpkg.com/tns-core-modules-widgets/-/tns-core-modules-widgets-3.1.0-2017-05-17-291.tgz#d3d6df5c75b58ba4b8737aa4ee47ae7375fd26d3"
26342634

2635-
tns-core-modules@~3.0.0:
2636-
version "3.0.0"
2637-
resolved "https://registry.yarnpkg.com/tns-core-modules/-/tns-core-modules-3.0.0.tgz#be0a538d3924a48320e9a875a1d351c664a3c9ab"
2635+
tns-core-modules@next:
2636+
version "3.1.0-2017-05-19-6648"
2637+
resolved "https://registry.yarnpkg.com/tns-core-modules/-/tns-core-modules-3.1.0-2017-05-19-6648.tgz#ce49b16419cb5695f7854a1a4d1ec6b7632002e5"
26382638
dependencies:
2639-
tns-core-modules-widgets "3.0.0"
2639+
tns-core-modules-widgets next
26402640

26412641
to-arraybuffer@^1.0.0:
26422642
version "1.0.1"
@@ -2675,7 +2675,7 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
26752675
version "0.14.5"
26762676
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
26772677

2678-
typescript@~2.3.1:
2678+
typescript@~2.3.2:
26792679
version "2.3.2"
26802680
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"
26812681

@@ -2784,9 +2784,9 @@ webpack-sources@^0.2.3, webpack-sources@~0.2.3:
27842784
source-list-map "^1.1.1"
27852785
source-map "~0.5.3"
27862786

2787-
webpack@~2.4.1:
2788-
version "2.4.1"
2789-
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.4.1.tgz#15a91dbe34966d8a4b99c7d656efd92a2e5a6f6a"
2787+
webpack@~2.5.1:
2788+
version "2.5.1"
2789+
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.5.1.tgz#61742f0cf8af555b87460a9cd8bba2f1e3ee2fce"
27902790
dependencies:
27912791
acorn "^5.0.0"
27922792
acorn-dynamic-import "^2.0.0"

0 commit comments

Comments
 (0)