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

Commit 273dbd5

Browse files
feat: Configure the vendor scripts to also use less, sass, scss for app.css (#343)
This will make the apps able to use app.scss instead of app.css without additional manual reconfiguration.
1 parent 4a5bedc commit 273dbd5

8 files changed

+22
-31
lines changed
File renamed without changes.
File renamed without changes.

Diff for: demo/TypeScriptApp/app/bundle-config.ts

-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@ if ((<any>global).TNS_WEBPACK) {
66
// This will register each xml, css, js, ts, scss etc. in the app/ folder
77
const context = (<any>require).context("~/", true, /page\.(xml|css|js|ts|scss)$/);
88
global.registerWebpackModules(context);
9-
10-
console.log("Register:");
11-
context.keys().forEach(key => {
12-
console.log(" - " + key);
13-
});
14-
159
}

Diff for: templates/vendor.angular.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Snapshot the ~/app.css and the theme
22
const application = require("application");
33
require("ui/styling/style-scope");
4-
global.registerModule("app.css", function() { return require("~/app.css"); });
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
56
application.loadAppCss();
67

78
require("./vendor-platform");

Diff for: templates/vendor.nativescript.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Snapshot the ~/app.css and the theme
22
const application = require("application");
33
require("ui/styling/style-scope");
4-
global.registerModule("app.css", function() { return require("~/app.css"); });
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
56
application.loadAppCss();
67

78
require("./vendor-platform");

Diff for: templates/webpack.angular.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module.exports = env => {
1414
throw new Error("You need to provide a target platform!");
1515
}
1616
const platforms = ["ios", "android"];
17-
const mainSheet = "app.css";
1817
const { snapshot, uglify, report, aot } = env;
1918
const ngToolsWebpackOptions = { tsConfigPath: aot ? "tsconfig.aot.json" : "tsconfig.json"};
2019

@@ -59,12 +58,15 @@ module.exports = env => {
5958
module: {
6059
rules: [
6160
{ test: /\.html$|\.xml$/, use: "raw-loader" },
62-
// Root stylesheet gets extracted with bundled dependencies
63-
{ test: new RegExp(mainSheet), use: "css-loader?url=false" },
64-
// Other CSS files get bundled using the raw loader
65-
{ test: /\.css$/, exclude: new RegExp(mainSheet), use: "raw-loader" },
66-
// SASS support
67-
{ test: /\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
61+
62+
// tns-core-modules reads the app.css and its imports using css-loader
63+
{ test: /^.\/app\.css$/, use: "css-loader?url=false" },
64+
{ test: /^.\/app\.scss$/, use: ["css-loader?url=false", "sass-loader"] },
65+
66+
// Angular components reference css files and their imports using raw-loader
67+
{ test: /\.css$/, exclude: /^.\/app\.css$/, use: "raw-loader" },
68+
{ test: /\.scss$/, exclude: /^.\/app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
69+
6870
// Compile TypeScript files with ahead-of-time compiler.
6971
{ test: /.ts$/, loader: "@ngtools/webpack" },
7072
],

Diff for: templates/webpack.javascript.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = env => {
1313
throw new Error("You need to provide a target platform!");
1414
}
1515
const platforms = ["ios", "android"];
16-
const mainSheet = "app.css";
1716
const { snapshot, uglify, report } = env;
1817

1918
const config = {
@@ -56,13 +55,10 @@ module.exports = env => {
5655
},
5756
module: {
5857
rules: [
59-
{ test: /\.html$|\.xml$/, use: "raw-loader" },
60-
// Root stylesheet gets extracted with bundled dependencies
61-
{ test: new RegExp(mainSheet), use: "css-loader?url=false" },
62-
// Other CSS files get bundled using the raw loader
63-
{ test: /\.css$/, exclude: new RegExp(mainSheet), use: "raw-loader" },
64-
// SASS support
65-
{ test: /\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
58+
{ test: /\.(html|xml)$/, use: "raw-loader" },
59+
60+
{ test: /\.css$/, use: "css-loader?url=false" },
61+
{ test: /\.scss$/, use: ["css-loader?url=false", "sass-loader"] },
6662
]
6763
},
6864
plugins: [

Diff for: templates/webpack.typescript.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,11 @@ module.exports = env => {
5656
},
5757
module: {
5858
rules: [
59-
{ test: /\.html$|\.xml$/, use: "raw-loader" },
60-
// Root stylesheet gets extracted with bundled dependencies
61-
{ test: new RegExp(mainSheet), use: "css-loader?url=false" },
62-
// Other CSS files get bundled using the raw loader
63-
{ test: /\.css$/, exclude: new RegExp(mainSheet), use: "raw-loader" },
64-
// SASS support
65-
{ test: /\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
66-
// Compile TypeScript files, replace templateUrl and styleUrls.
59+
{ test: /\.(html|xml)$/, use: "raw-loader" },
60+
61+
{ test: /\.css$/, use: "css-loader?url=false" },
62+
{ test: /\.scss$/, use: ["css-loader?url=false", "sass-loader"] },
63+
6764
{ test: /\.ts$/, use: "awesome-typescript-loader" }
6865
]
6966
},

0 commit comments

Comments
 (0)