Skip to content

Commit e4b9842

Browse files
committed
Upgrade nativescript-dev-webpack
Part of a fix outlined in NativeScript/nativescript-cli#4392 (comment)
1 parent 0078d46 commit e4b9842

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@ngtools/webpack": "~7.2.0",
4343
"nativescript": "^5.3.0-2019-03-20-13061",
4444
"nativescript-dev-typescript": "~0.8.0",
45-
"nativescript-dev-webpack": "~0.20.0"
45+
"nativescript-dev-webpack": "^0.21.0-next-2019-03-20-200603-01"
4646
},
4747
"scripts": {
4848
"test": "tns test",

webpack.config.js

+34-16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = env => {
4747
report, // --env.report
4848
sourceMap, // --env.sourceMap
4949
hmr, // --env.hmr,
50+
unitTesting, // --env.unitTesting
5051
} = env;
5152

5253
const externals = nsWebpack.getConvertedExternals(env.externals);
@@ -55,6 +56,11 @@ module.exports = env => {
5556
const tsConfigName = "tsconfig.tns.json";
5657
const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
5758
const entryPath = `.${sep}${entryModule}`;
59+
const entries = { bundle: entryPath };
60+
if (platform === "ios") {
61+
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
62+
};
63+
5864
const ngCompilerTransformers = [];
5965
const additionalLazyModuleResources = [];
6066
if (aot) {
@@ -101,9 +107,7 @@ module.exports = env => {
101107
]
102108
},
103109
target: nativescriptTarget,
104-
entry: {
105-
bundle: entryPath,
106-
},
110+
entry: entries,
107111
output: {
108112
pathinfo: false,
109113
path: dist,
@@ -139,6 +143,7 @@ module.exports = env => {
139143
},
140144
devtool: sourceMap ? "inline-source-map" : "none",
141145
optimization: {
146+
runtimeChunk: "single",
142147
splitChunks: {
143148
cacheGroups: {
144149
vendor: {
@@ -175,7 +180,7 @@ module.exports = env => {
175180
module: {
176181
rules: [
177182
{
178-
test: new RegExp(entryPath),
183+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
179184
use: [
180185
// Require all Android app components
181186
platform === "android" && {
@@ -188,6 +193,9 @@ module.exports = env => {
188193
options: {
189194
angular: true,
190195
loadCss: !snapshot, // load the application css if in debug mode
196+
unitTesting,
197+
appFullPath,
198+
projectRoot,
191199
}
192200
},
193201
].filter(loader => !!loader)
@@ -241,25 +249,23 @@ module.exports = env => {
241249
}),
242250
// Remove all files from the out dir.
243251
new CleanWebpackPlugin([`${dist}/**/*`]),
244-
// Copy native app resources to out dir.
245-
new CopyWebpackPlugin([
246-
{
247-
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
248-
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
249-
context: projectRoot
250-
},
251-
]),
252252
// Copy assets to out dir. Add your own globs as needed.
253253
new CopyWebpackPlugin([
254254
{ from: { glob: "fonts/**" } },
255255
{ from: { glob: "**/*.jpg" } },
256256
{ from: { glob: "**/*.png" } },
257257
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
258258
// Generate a bundle starter script and activate it in package.json
259-
new nsWebpack.GenerateBundleStarterPlugin([
260-
"./vendor",
261-
"./bundle",
262-
]),
259+
new nsWebpack.GenerateBundleStarterPlugin(
260+
// Don't include `runtime.js` when creating a snapshot. The plugin
261+
// configures the WebPack runtime to be generated inside the snapshot
262+
// module and no `runtime.js` module exist.
263+
(snapshot ? [] : ["./runtime"])
264+
.concat([
265+
"./vendor",
266+
"./bundle",
267+
])
268+
),
263269
// For instructions on how to set up workers with webpack
264270
// check out https://github.com/nativescript/worker-loader
265271
new NativeScriptWorkerPlugin(),
@@ -269,6 +275,18 @@ module.exports = env => {
269275
],
270276
};
271277

278+
// Copy the native app resources to the out dir
279+
// only if doing a full build (tns run/build) and not previewing (tns preview)
280+
if (!externals || externals.length === 0) {
281+
config.plugins.push(new CopyWebpackPlugin([
282+
{
283+
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
284+
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
285+
context: projectRoot
286+
},
287+
]));
288+
}
289+
272290

273291
if (report) {
274292
// Generate report files for bundles content

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4201,10 +4201,10 @@ nativescript-dev-typescript@~0.8.0:
42014201
semver "5.5.0"
42024202
typescript "~3.1.1"
42034203

4204-
nativescript-dev-webpack@~0.20.0:
4205-
version "0.20.3"
4206-
resolved "https://registry.yarnpkg.com/nativescript-dev-webpack/-/nativescript-dev-webpack-0.20.3.tgz#62ab41cc5308be7ca4496db92a6fe6ae2af6fa0a"
4207-
integrity sha512-j3MsSWTyYteMBmljW4kFAGwvAcE+46QA3VH18kA8vXhmwGne/J8a5CDeI0a5jp+0ecDfm74oyRjLZur6j7AtKw==
4204+
nativescript-dev-webpack@^0.21.0-next-2019-03-20-200603-01:
4205+
version "0.21.0-next-2019-03-20-200603-01"
4206+
resolved "https://registry.yarnpkg.com/nativescript-dev-webpack/-/nativescript-dev-webpack-0.21.0-next-2019-03-20-200603-01.tgz#f4a41878cd275f736973265237e86ef94ae2ac54"
4207+
integrity sha512-+pin6VI6iiWR82ANVxPwH8QEhckD/UAXBFyG2Sxm4fHOFmqXivFTI8bby8SvbItuGXUuzW0ZDEJuCaJ0xD378g==
42084208
dependencies:
42094209
"@angular-devkit/core" "~7.2.0"
42104210
clean-webpack-plugin "~1.0.0"

0 commit comments

Comments
 (0)