Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit f9bbea9

Browse files
committed
feat: load bundle config and app css at build time
This will remove the need of a default bundle-config.js file in the app templates.
1 parent d02bd91 commit f9bbea9

File tree

13 files changed

+102
-64
lines changed

13 files changed

+102
-64
lines changed

bundle-config-loader.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = function(source) {
2+
this.cacheable();
3+
const { registerPages, loadCss } = this.query;
4+
5+
if (registerPages) {
6+
source = `
7+
require("nativescript-dev-webpack/register-modules");
8+
${source}
9+
`;
10+
}
11+
12+
if (loadCss) {
13+
source = `
14+
require("nativescript-dev-webpack/load-application-css");
15+
${source}
16+
`;
17+
}
18+
19+
this.callback(null, source);
20+
};
21+

demo/JavaScriptApp/app/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ You can use this file to perform app-level initialization, but the primary
44
purpose of the file is to pass control to the app’s first module.
55
*/
66

7-
require("./bundle-config");
87
var application = require("application");
98

109
application.start({ moduleName: "main-page" });

demo/JavaScriptApp/app/bundle-config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

demo/TypeScriptApp/app/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ You can use this file to perform app-level initialization, but the primary
44
purpose of the file is to pass control to the app’s first module.
55
*/
66

7-
import "./bundle-config";
87
import * as app from 'application';
98

109
app.start({ moduleName: 'main-page' });

demo/TypeScriptApp/app/bundle-config.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

demo/TypeScriptApp/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"*": [
1616
"./node_modules/tns-core-modules/*",
1717
"./node_modules/*"
18+
],
19+
"~/*": [
20+
"app/*"
1821
]
1922
}
2023
},

load-application-css.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const application = require("application");
2+
require("ui/styling/style-scope");
3+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
4+
global.registerWebpackModules(appCssContext);
5+
application.loadAppCss();
6+

plugins/NativeScriptSnapshotPlugin/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ exports.NativeScriptSnapshotPlugin = (function() {
3434
}
3535

3636
NativeScriptSnapshotPlugin.ensureSnapshotModuleEntry = function(options) {
37-
const { webpackConfig, requireModules, chunks, projectRoot } = options;
37+
const { webpackConfig, requireModules, chunks, projectRoot, includeApplicationCss } = options;
3838

3939
const androidProjectPath = getAndroidProjectPath({ projectRoot: projectRoot });
4040
const snapshotEntryPath = join(androidProjectPath, SNAPSHOT_ENTRY_MODULE);
41-
const snapshotEntryContent = requireModules.map(mod => `require('${mod}')`).join(";");
41+
42+
let snapshotEntryContent = "";
43+
if (includeApplicationCss) {
44+
snapshotEntryContent += `require("nativescript-dev-webpack/load-application-css");`;
45+
}
46+
snapshotEntryContent += requireModules.map(mod => `require('${mod}')`).join(";");
47+
4248
writeFileSync(snapshotEntryPath, snapshotEntryContent, { encoding: "utf8" });
4349

4450
// add the module to the entry points to make sure it's content is evaluated

plugins/NativeScriptSnapshotPlugin/options.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
"requireModules": {
4343
"type": "array",
4444
"default": []
45+
},
46+
"includeApplicationCss": {
47+
"type": "boolean",
48+
"default": true
4549
}
4650
},
4751
"required": [

register-modules.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require("tns-core-modules/bundle-entry-points");
2+
const context = require.context("~/", true, /(root|page|fragment)\.(xml|css|js|ts|scss)$/);
3+
global.registerWebpackModules(context);
4+

0 commit comments

Comments
 (0)