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

Commit 2a71d03

Browse files
committed
Support app.css bundling + theme CSS imports.
1 parent 9f80a9d commit 2a71d03

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

platform-css-loader.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var cssSuffixMatcher = /(@import.*)\.css/g;
2+
var themeMatcher = /(@import[^'"]*)(['"]~?\/?)nativescript-theme-core(.*)/g;
3+
4+
module.exports = function(source, sourcemap) {
5+
var newSource = source.replace(cssSuffixMatcher, function (fullMatch, importPrefix) {
6+
return importPrefix;
7+
}).replace(themeMatcher, function(fullMatch, importPrefix, pathStart, rest) {
8+
var quote = pathStart[0];
9+
return importPrefix + quote + "~nativescript-theme-core" + rest;
10+
});
11+
12+
// Support for tests
13+
if (this.callback) {
14+
this.callback(null, newSource, sourcemap);
15+
} else {
16+
return newSource;
17+
}
18+
};

postinstall.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ configureDevDependencies(packageJson, function(add) {
4545
add("awesome-typescript-loader", "~2.2.4");
4646
add("angular2-template-loader", "~0.6.0");
4747
add("raw-loader", "~0.5.1");
48+
add("css-loader", "~0.26.0");
49+
add("resolve-url-loader", "~1.6.0");
50+
add("extract-text-webpack-plugin", "~2.0.0-beta.4");
4851
});
4952

5053
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4));

webpack.common.js.template

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var webpack = require("webpack");
22
var nsWebpack = require("nativescript-dev-webpack");
33
var path = require("path");
44
var CopyWebpackPlugin = require("copy-webpack-plugin");
5+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
56
var path = require("path");
67

78
module.exports = function(platform, destinationApp) {
@@ -14,6 +15,8 @@ module.exports = function(platform, destinationApp) {
1415
entry.bundle = "./" + nsWebpack.getEntryModule();
1516
//Vendor entry with third party libraries.
1617
entry.vendor = "./vendor";
18+
//app.css bundle
19+
entry["app.css"] = "./app.css";
1720

1821
return {
1922
context: path.resolve("./app"),
@@ -30,8 +33,10 @@ module.exports = function(platform, destinationApp) {
3033
extensions: [
3134
".ts",
3235
".js",
36+
".css",
3337
"." + platform + ".ts",
3438
"." + platform + ".js",
39+
"." + platform + ".css",
3540
],
3641
//Resolve {N} system modules from tns-core-modules
3742
modules: [
@@ -51,28 +56,44 @@ module.exports = function(platform, destinationApp) {
5156
test: /\.html$/,
5257
loader: "raw-loader"
5358
},
59+
// Root app.css file gets extracted with bundled dependencies
60+
{
61+
test: /app\.css$/,
62+
loader: ExtractTextPlugin.extract([
63+
"resolve-url-loader",
64+
"css-loader",
65+
"nativescript-dev-webpack/platform-css-loader",
66+
]),
67+
},
68+
// Other CSS files get bundled using the raw loader
5469
{
5570
test: /\.css$/,
56-
loader: "raw-loader"
71+
exclude: /app\.css$/,
72+
loaders: [
73+
"raw-loader",
74+
]
5775
},
76+
// Compile TypeScript files, replace templateUrl and styleUrls.
5877
{
5978
test: /\.ts$/,
6079
loaders: [
6180
"awesome-typescript-loader",
6281
"angular2-template-loader"
6382
]
6483
},
84+
// SASS support
6585
{
6686
test: /\.scss$/,
6787
loaders: [
6888
"raw-loader",
69-
"resolve-url",
89+
"resolve-url-loader",
7090
"sass-loader"
7191
]
7292
},
7393
]
7494
},
7595
plugins: [
96+
new ExtractTextPlugin("app.css"),
7697
//Vendor libs go to the vendor.js chunk
7798
new webpack.optimize.CommonsChunkPlugin({
7899
name: ["vendor"]
@@ -98,6 +119,6 @@ module.exports = function(platform, destinationApp) {
98119
]),
99120
//Required for bundle chunks loading
100121
new nsWebpack.NativeScriptJsonpPlugin(),
101-
]
122+
],
102123
};
103124
};

0 commit comments

Comments
 (0)