Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit69ace1e

Browse files
feat: allow extending webpack.config.js through env
In case you need to extend the webpack.config.js, currently you cannot extend everything and you need to write a lot of custom logic. This PR adds the possibility to extend the appComponents, entries and alias through `env`.Also update demo applications to use latest CLI feature for extending webpack.config.js
1 parente95287d commit69ace1e

17 files changed

+122
-63
lines changed

‎demo/AngularApp/app/App_Resources/Android/app.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
//compile 'com.android.support:recyclerview-v7:+'
66
//}
77

8-
android {
9-
defaultConfig {
8+
android {
9+
defaultConfig {
1010
generatedDensities= []
11-
applicationId="org.nativescript.AngularApp"
12-
}
13-
aaptOptions {
14-
additionalParameters"--no-version-vectors"
15-
}
16-
}
11+
}
12+
aaptOptions {
13+
additionalParameters"--no-version-vectors"
14+
}
15+
}

‎demo/AngularApp/app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"android": {
3-
"v8Flags":"--expose_gc"
3+
"v8Flags":"--expose_gc",
4+
"markingMode":"none"
45
},
56
"main":"main.js",
67
"name":"tns-template-hello-world-ng",
78
"version":"3.3.0"
8-
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
constwebpackConfig=require("./webpack.config");
2+
constpath=require("path");
3+
4+
module.exports=env=>{
5+
env=env||{};
6+
env.appComponents=env.appComponents||[];
7+
env.appComponents.push(path.resolve(__dirname,"app/activity.android.ts"));
8+
9+
env.entries=env.entries||{};
10+
env.entries.application="./application.android";
11+
constconfig=webpackConfig(env);
12+
returnconfig;
13+
};

‎demo/AngularApp/nsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"webpackConfigPath":"custom-application-activity.webpack.config.js"
3+
}

‎demo/AngularApp/webpack.config.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ const hashSalt = Date.now().toString();
1818

1919
module.exports=env=>{
2020
// Add your custom Activities, Services and other Android app components here.
21-
constappComponents=[
21+
constappComponents=env.appComponents||[];
22+
appComponents.push(...[
2223
"tns-core-modules/ui/frame",
2324
"tns-core-modules/ui/frame/activity",
24-
resolve(__dirname,"app/activity.android.ts")
25-
];
25+
]);
2626

2727
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2828
if(!platform){
@@ -66,9 +66,8 @@ module.exports = env => {
6666
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
6767
consthasRootLevelScopedAngular=nsWebpack.hasRootLevelScopedAngular({projectDir:projectRoot});
6868
letcoreModulesPackageName="tns-core-modules";
69-
constalias={
70-
'~':appFullPath
71-
};
69+
constalias=env.alias||{};
70+
alias['~']=appFullPath;
7271

7372
constcompilerOptions=getCompilerOptionsFromTSConfig(tsConfigPath);
7473
if(hasRootLevelScopedModules){
@@ -85,7 +84,9 @@ module.exports = env => {
8584
constappResourcesFullPath=resolve(projectRoot,appResourcesPath);
8685
constentryModule=`${nsWebpack.getEntryModule(appFullPath,platform)}.ts`;
8786
constentryPath=`.${sep}${entryModule}`;
88-
constentries={bundle:entryPath,application:"./application.android"};
87+
constentries=env.entries||{};
88+
entries.bundle=entryPath;
89+
8990
constareCoreModulesExternal=Array.isArray(env.externals)&&env.externals.some(e=>e.indexOf("tns-core-modules")>-1);
9091
if(platform==="ios"&&!areCoreModulesExternal){
9192
entries["tns_modules/tns-core-modules/inspector_modules"]="inspector_modules";

‎demo/JavaScriptApp/app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"android": {
3-
"v8Flags":"--expose_gc"
3+
"v8Flags":"--expose_gc",
4+
"markingMode":"none"
45
},
56
"main":"app.js",
67
"name":"tns-template-hello-world",
78
"version":"3.3.0"
8-
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
constwebpackConfig=require("./webpack.config");
2+
constpath=require("path");
3+
4+
module.exports=env=>{
5+
env=env||{};
6+
env.appComponents=env.appComponents||[];
7+
env.appComponents.push(path.resolve(__dirname,"app/activity.android.js"));
8+
9+
env.entries=env.entries||{};
10+
env.entries.application="./application.android";
11+
constconfig=webpackConfig(env);
12+
returnconfig;
13+
};

‎demo/JavaScriptApp/nsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"webpackConfigPath":"./custom-application-activity.webpack.config.js"
3+
}

‎demo/JavaScriptApp/webpack.config.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const hashSalt = Date.now().toString();
1212

1313
module.exports=env=>{
1414
// Add your custom Activities, Services and other android app components here.
15-
constappComponents=[
15+
constappComponents=env.appComponents||[];
16+
appComponents.push(...[
1617
"tns-core-modules/ui/frame",
1718
"tns-core-modules/ui/frame/activity",
18-
resolve(__dirname,"app/activity.android.js")
19-
];
19+
]);
2020

2121
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2222
if(!platform){
@@ -56,9 +56,8 @@ module.exports = env => {
5656
constappFullPath=resolve(projectRoot,appPath);
5757
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
5858
letcoreModulesPackageName="tns-core-modules";
59-
constalias={
60-
'~':appFullPath
61-
};
59+
constalias=env.alias||{};
60+
alias['~']=appFullPath;
6261

6362
if(hasRootLevelScopedModules){
6463
coreModulesPackageName="@nativescript/core";
@@ -68,7 +67,9 @@ module.exports = env => {
6867

6968
constentryModule=nsWebpack.getEntryModule(appFullPath,platform);
7069
constentryPath=`.${sep}${entryModule}.js`;
71-
constentries={bundle:entryPath,application:"./application.android"};
70+
constentries=env.entries||{};
71+
entries.bundle=entryPath;
72+
7273
constareCoreModulesExternal=Array.isArray(env.externals)&&env.externals.some(e=>e.indexOf("tns-core-modules")>-1);
7374
if(platform==="ios"&&!areCoreModulesExternal){
7475
entries["tns_modules/tns-core-modules/inspector_modules"]="inspector_modules";
@@ -82,6 +83,7 @@ module.exports = env => {
8283
itemsToClean.push(`${join(projectRoot,"platforms","android","app","build","configurations","nativescript-android-snapshot")}`);
8384
}
8485

86+
8587
nsWebpack.processAppComponents(appComponents,platform);
8688
constconfig={
8789
mode:production ?"production" :"development",
@@ -109,6 +111,8 @@ module.exports = env => {
109111
extensions:[".js",".scss",".css"],
110112
// Resolve {N} system modules from tns-core-modules
111113
modules:[
114+
resolve(__dirname,`node_modules/${coreModulesPackageName}`),
115+
resolve(__dirname,"node_modules"),
112116
`node_modules/${coreModulesPackageName}`,
113117
"node_modules",
114118
],
@@ -272,4 +276,4 @@ module.exports = env => {
272276

273277

274278
returnconfig;
275-
};
279+
};

‎demo/TypeScriptApp/app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"android": {
3-
"v8Flags":"--expose_gc"
3+
"v8Flags":"--expose_gc",
4+
"markingMode":"none"
45
},
56
"main":"app.js",
67
"name":"tns-template-hello-world-ts",
78
"version":"3.3.0"
8-
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
constwebpackConfig=require("./webpack.config");
2+
constpath=require("path");
3+
4+
module.exports=env=>{
5+
env=env||{};
6+
env.appComponents=env.appComponents||[];
7+
env.appComponents.push(path.resolve(__dirname,"app/activity.android.ts"));
8+
9+
env.entries=env.entries||{};
10+
env.entries.application="./application.android";
11+
constconfig=webpackConfig(env);
12+
returnconfig;
13+
};

‎demo/TypeScriptApp/nsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"useLegacyWorkflow":false
2+
"webpackConfigPath":"./custom-application-activity.webpack.config.js"
33
}

‎demo/TypeScriptApp/webpack.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const hashSalt = Date.now().toString();
1414

1515
module.exports=env=>{
1616
// Add your custom Activities, Services and other Android app components here.
17-
constappComponents=[
17+
constappComponents=env.appComponents||[];
18+
appComponents.push(...[
1819
"tns-core-modules/ui/frame",
1920
"tns-core-modules/ui/frame/activity",
20-
resolve(__dirname,"app/activity.android.ts")
21-
];
21+
]);
2222

2323
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2424
if(!platform){
@@ -59,9 +59,8 @@ module.exports = env => {
5959
constappFullPath=resolve(projectRoot,appPath);
6060
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
6161
letcoreModulesPackageName="tns-core-modules";
62-
constalias={
63-
'~':appFullPath
64-
};
62+
constalias=env.alias||{};
63+
alias['~']=appFullPath;
6564

6665
if(hasRootLevelScopedModules){
6766
coreModulesPackageName="@nativescript/core";
@@ -71,7 +70,8 @@ module.exports = env => {
7170

7271
constentryModule=nsWebpack.getEntryModule(appFullPath,platform);
7372
constentryPath=`.${sep}${entryModule}.ts`;
74-
constentries={bundle:entryPath,application:"./application.android"};
73+
constentries=env.entries||{};
74+
entries.bundle=entryPath;
7575

7676
consttsConfigPath=resolve(projectRoot,"tsconfig.tns.json");
7777

‎templates/webpack.angular.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ const hashSalt = Date.now().toString();
1818

1919
module.exports=env=>{
2020
// Add your custom Activities, Services and other Android app components here.
21-
constappComponents=[
21+
constappComponents=env.appComponents||[];
22+
appComponents.push(...[
2223
"tns-core-modules/ui/frame",
2324
"tns-core-modules/ui/frame/activity",
24-
];
25+
]);
2526

2627
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2728
if(!platform){
@@ -65,9 +66,8 @@ module.exports = env => {
6566
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
6667
consthasRootLevelScopedAngular=nsWebpack.hasRootLevelScopedAngular({projectDir:projectRoot});
6768
letcoreModulesPackageName="tns-core-modules";
68-
constalias={
69-
'~':appFullPath
70-
};
69+
constalias=env.alias||{};
70+
alias['~']=appFullPath;
7171

7272
constcompilerOptions=getCompilerOptionsFromTSConfig(tsConfigPath);
7373
if(hasRootLevelScopedModules){
@@ -84,7 +84,9 @@ module.exports = env => {
8484
constappResourcesFullPath=resolve(projectRoot,appResourcesPath);
8585
constentryModule=`${nsWebpack.getEntryModule(appFullPath,platform)}.ts`;
8686
constentryPath=`.${sep}${entryModule}`;
87-
constentries={bundle:entryPath};
87+
constentries=env.entries||{};
88+
entries.bundle=entryPath;
89+
8890
constareCoreModulesExternal=Array.isArray(env.externals)&&env.externals.some(e=>e.indexOf("tns-core-modules")>-1);
8991
if(platform==="ios"&&!areCoreModulesExternal){
9092
entries["tns_modules/tns-core-modules/inspector_modules"]="inspector_modules";

‎templates/webpack.javascript.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ const hashSalt = Date.now().toString();
1212

1313
module.exports=env=>{
1414
// Add your custom Activities, Services and other android app components here.
15-
constappComponents=[
15+
constappComponents=env.appComponents||[];
16+
appComponents.push(...[
1617
"tns-core-modules/ui/frame",
1718
"tns-core-modules/ui/frame/activity",
18-
];
19+
]);
1920

2021
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2122
if(!platform){
@@ -55,9 +56,8 @@ module.exports = env => {
5556
constappFullPath=resolve(projectRoot,appPath);
5657
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
5758
letcoreModulesPackageName="tns-core-modules";
58-
constalias={
59-
'~':appFullPath
60-
};
59+
constalias=env.alias||{};
60+
alias['~']=appFullPath;
6161

6262
if(hasRootLevelScopedModules){
6363
coreModulesPackageName="@nativescript/core";
@@ -67,7 +67,9 @@ module.exports = env => {
6767

6868
constentryModule=nsWebpack.getEntryModule(appFullPath,platform);
6969
constentryPath=`.${sep}${entryModule}.js`;
70-
constentries={bundle:entryPath};
70+
constentries=env.entries||{};
71+
entries.bundle=entryPath;
72+
7173
constareCoreModulesExternal=Array.isArray(env.externals)&&env.externals.some(e=>e.indexOf("tns-core-modules")>-1);
7274
if(platform==="ios"&&!areCoreModulesExternal){
7375
entries["tns_modules/tns-core-modules/inspector_modules"]="inspector_modules";

‎templates/webpack.typescript.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const hashSalt = Date.now().toString();
1414

1515
module.exports=env=>{
1616
// Add your custom Activities, Services and other Android app components here.
17-
constappComponents=[
17+
constappComponents=env.appComponents||[];
18+
appComponents.push(...[
1819
"tns-core-modules/ui/frame",
1920
"tns-core-modules/ui/frame/activity",
20-
];
21+
]);
2122

2223
constplatform=env&&(env.android&&"android"||env.ios&&"ios");
2324
if(!platform){
@@ -58,9 +59,8 @@ module.exports = env => {
5859
constappFullPath=resolve(projectRoot,appPath);
5960
consthasRootLevelScopedModules=nsWebpack.hasRootLevelScopedModules({projectDir:projectRoot});
6061
letcoreModulesPackageName="tns-core-modules";
61-
constalias={
62-
'~':appFullPath
63-
};
62+
constalias=env.alias||{};
63+
alias['~']=appFullPath;
6464

6565
if(hasRootLevelScopedModules){
6666
coreModulesPackageName="@nativescript/core";
@@ -70,7 +70,8 @@ module.exports = env => {
7070

7171
constentryModule=nsWebpack.getEntryModule(appFullPath,platform);
7272
constentryPath=`.${sep}${entryModule}.ts`;
73-
constentries={bundle:entryPath};
73+
constentries=env.entries||{};
74+
entries.bundle=entryPath;
7475

7576
consttsConfigPath=resolve(projectRoot,"tsconfig.tns.json");
7677

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp