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

Commit 7783002

Browse files
committed
Add the PlatformFSPlugin, remove ExtractTextPlugin, use latest css-loader, snapshot the app.css
1 parent ed392e5 commit 7783002

16 files changed

+109
-167
lines changed

Diff for: dependencyManager.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function getRequiredDeps(packageJson) {
6363
"webpack-sources": "~1.0.1",
6464
"copy-webpack-plugin": "~4.0.1",
6565
"raw-loader": "~0.5.1",
66-
"nativescript-css-loader": "~0.26.0",
66+
"css-loader": "~0.28.7",
6767
"nativescript-worker-loader": "~0.8.1",
6868
"resolve-url-loader": "~2.1.0",
6969
"extract-text-webpack-plugin": "~3.0.0",
@@ -97,9 +97,9 @@ function resolveAngularDeps(usedDependencies) {
9797
"@ngtools/webpack": "1.2.13",
9898
});
9999
} else {
100-
Object.assign(depsToAdd, {
100+
Object.assign(depsToAdd, {
101101
"typescript": "~2.3.4",
102-
"@ngtools/webpack": "~1.6.0",
102+
"@ngtools/webpack": "1.8.0-rc.3",
103103
});
104104
}
105105

Diff for: plugins/PlatformFSPlugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function PlatformFSPlugin({platform, platforms, ignore}) {
1313
})).map(({endsWithSuffix, contains}) => baseFileName =>
1414
baseFileName.endsWith(endsWithSuffix) ||
1515
baseFileName.indexOf(contains) != -1);
16-
this.isNotAlienPlatformFile = file => !alienPlatformFilters.some(basename(file));
16+
this.isNotAlienPlatformFile = file => !alienPlatformFilters.some(filter => filter(basename(file)));
1717

1818
const currentPlatformExt = `.${platform}`;
1919
this.trimPlatformSuffix = file => {
@@ -54,7 +54,7 @@ PlatformFSPlugin.prototype.mapFileSystem = function(fs) {
5454
get _readdirStorage() { return fs._readdirStorage; }
5555
};
5656

57-
["readFile", "provide", "stat", "readJson"].forEach(mapPath);
57+
["readFile", "provide", "stat", "readJson", "readlink"].forEach(mapPath);
5858
["readdir"].forEach(filterResultingFiles);
5959

6060
return mappedFS;

Diff for: prepublish/angular/getExtensions.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
module.exports = `
2-
// Resolve platform-specific modules like module.android.js
3-
function getExtensions(platform) {
4-
return Object.freeze([
5-
\`.\${platform}.ts\`,
6-
\`.\${platform}.js\`,
7-
".aot.ts",
8-
".ts",
9-
".js",
10-
".css",
11-
\`.\${platform}.css\`,
12-
]);
13-
}
14-
`;
1+
module.exports = `[ ".aot.ts", ".ts", ".js", ".css" ]`;

Diff for: prepublish/angular/plugins.js

-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,4 @@ module.exports = `
66
typeChecking: false
77
}, ngToolsWebpackOptions)
88
),
9-
10-
// Resolve .ios.css and .android.css component stylesheets, and .ios.html and .android component views
11-
new nsWebpack.UrlResolvePlugin({
12-
platform: platform,
13-
resolveStylesUrls: true,
14-
resolveTemplateUrl: true
15-
}),
169
`;

Diff for: prepublish/common/exports.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = `
1+
module.exports = ({extensions}) => `
22
const mainSheet = \`app.css\`;
33
44
module.exports = env => {
@@ -20,7 +20,6 @@ module.exports = env => {
2020
2121
const rules = getRules();
2222
const plugins = getPlugins(platform, env);
23-
const extensions = getExtensions(platform);
2423
2524
const config = {
2625
context: resolve("./app"),
@@ -33,7 +32,7 @@ module.exports = env => {
3332
filename: "[name].js",
3433
},
3534
resolve: {
36-
extensions,
35+
extensions: ${extensions},
3736
3837
// Resolve {N} system modules from tns-core-modules
3938
modules: [
@@ -49,6 +48,11 @@ module.exports = env => {
4948
// and will enable us to work with symlinked packages during development.
5049
symlinks: false
5150
},
51+
resolveLoader: {
52+
// This will not follow symlinks to their original location,
53+
// and will enable us to work with symlinked loaders during development.
54+
symlinks: false
55+
},
5256
node: {
5357
// Disable node shims that conflict with NativeScript
5458
"http": false,

Diff for: prepublish/common/imports.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = `const { resolve, join } = require("path");
22
33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
5+
const { PlatformFSPlugin } = require("nativescript-dev-webpack");
56
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
67
const CopyWebpackPlugin = require("copy-webpack-plugin");
78
const ExtractTextPlugin = require("extract-text-webpack-plugin");

Diff for: prepublish/common/plugins.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
module.exports = `
2-
new ExtractTextPlugin(mainSheet),
3-
42
// Vendor libs go to the vendor.js chunk
53
new webpack.optimize.CommonsChunkPlugin({
64
name: ["vendor"],
@@ -13,7 +11,6 @@ module.exports = `
1311
1412
// Copy assets to out dir. Add your own globs as needed.
1513
new CopyWebpackPlugin([
16-
{ from: mainSheet },
1714
{ from: "css/**" },
1815
{ from: "fonts/**" },
1916
{ from: "**/*.jpg" },
@@ -26,7 +23,7 @@ module.exports = `
2623
"./vendor",
2724
"./bundle",
2825
]),
29-
26+
3027
// Support for web workers since v3.2
3128
new NativeScriptWorkerPlugin(),
3229
@@ -37,4 +34,12 @@ module.exports = `
3734
generateStatsFile: true,
3835
reportFilename: join(__dirname, "report", \`report.html\`),
3936
statsFilename: join(__dirname, "report", \`stats.json\`),
37+
}),
38+
39+
// Setup compiler.inputFileSystem to map files to platform specific files when possible,
40+
// as well as filter ios specific files when building android and the vice-versa.
41+
new PlatformFSPlugin({
42+
platform,
43+
platforms: ["ios", "android"],
44+
ignore: ["App_Resources"]
4045
}),`;

Diff for: prepublish/common/rules.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ module.exports = `
88
// Root stylesheet gets extracted with bundled dependencies
99
{
1010
test: new RegExp(mainSheet),
11-
use: ExtractTextPlugin.extract([
12-
{
13-
loader: "resolve-url-loader",
14-
options: { silent: true },
15-
},
16-
{
17-
loader: "nativescript-css-loader",
18-
options: { minimize: false }
19-
},
20-
"nativescript-dev-webpack/platform-css-loader",
21-
]),
11+
use: [{
12+
loader: "css-loader?url=false",
13+
options: { url: false }
14+
}],
2215
},
2316
// Other CSS files get bundled using the raw loader
2417
{

Diff for: prepublish/index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ function saveTemplate(target) {
1212
function buildTemplate(target) {
1313
let template = "";
1414

15+
const extensions = require(`./${target}/getExtensions`);
16+
1517
template += getResource(target, "imports");
16-
template += getResource(target, "exports");
18+
template += getResource(target, "exports", { extensions });
1719
template += getResource(target, "getPlatform");
1820

1921
const rules = getResource(target, "rules");
@@ -22,14 +24,16 @@ function buildTemplate(target) {
2224
const plugins = getResource(target, "plugins");
2325
template += pluginsBuilder(plugins);
2426

25-
template += require(`./${target}/getExtensions`);
26-
2727
return template;
2828
};
2929

30-
function getResource(target, resourceName) {
31-
const common = require(`./common/${resourceName}`);
32-
const maybeSpecific = tryRequire(`./${target}/${resourceName}`);
30+
function applyArgs(stringOrTemplateFunction, args) {
31+
return typeof stringOrTemplateFunction === "function" ? stringOrTemplateFunction(args) : stringOrTemplateFunction;
32+
}
33+
34+
function getResource(target, resourceName, args) {
35+
let common = applyArgs(require(`./common/${resourceName}`), args);
36+
const maybeSpecific = applyArgs(tryRequire(`./${target}/${resourceName}`), args);
3337

3438
return merge(resourceName, common, maybeSpecific);
3539
}

Diff for: prepublish/javascript/getExtensions.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
module.exports = `
2-
// Resolve platform-specific modules like module.android.js
3-
function getExtensions(platform) {
4-
return Object.freeze([
5-
\`.\${platform}.js\`,
6-
".js",
7-
".css",
8-
\`.\${platform}.css\`,
9-
]);
10-
}
11-
`;
1+
module.exports = `[ ".js", ".css" ]`;

Diff for: prepublish/typescript/getExtensions.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
module.exports = `
2-
// Resolve platform-specific modules like module.android.js
3-
function getExtensions(platform) {
4-
return Object.freeze([
5-
\`.\${platform}.ts\`,
6-
\`.\${platform}.js\`,
7-
".ts",
8-
".js",
9-
".css",
10-
\`.\${platform}.css\`,
11-
]);
12-
}
13-
`;
1+
module.exports = `[ ".ts", ".js", ".css" ]`;

Diff for: templates/vendor.angular.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import * as application from "application";
2+
import "ui/styling/style-scope";
3+
global.registerModule("app.css", () => require("~/app.css"));
4+
application.loadAppCss();
5+
16
require("./vendor-platform");
27

38
require("reflect-metadata");

Diff for: templates/vendor.nativescript.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import * as application from "application";
2+
import "ui/styling/style-scope";
3+
global.registerModule("app.css", () => require("~/app.css"));
4+
application.loadAppCss();
5+
16
require("./vendor-platform");
27

38
require("bundle-entry-points");

Diff for: templates/webpack.angular.js

+20-37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { resolve, join } = require("path");
22

33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
5+
const { PlatformFSPlugin } = require("nativescript-dev-webpack");
56
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
67
const CopyWebpackPlugin = require("copy-webpack-plugin");
78
const ExtractTextPlugin = require("extract-text-webpack-plugin");
@@ -33,7 +34,6 @@ module.exports = env => {
3334

3435
const rules = getRules();
3536
const plugins = getPlugins(platform, env);
36-
const extensions = getExtensions(platform);
3737

3838
const config = {
3939
context: resolve("./app"),
@@ -46,7 +46,7 @@ module.exports = env => {
4646
filename: "[name].js",
4747
},
4848
resolve: {
49-
extensions,
49+
extensions: [ ".aot.ts", ".ts", ".js", ".css" ],
5050

5151
// Resolve {N} system modules from tns-core-modules
5252
modules: [
@@ -62,6 +62,11 @@ module.exports = env => {
6262
// and will enable us to work with symlinked packages during development.
6363
symlinks: false
6464
},
65+
resolveLoader: {
66+
// This will not follow symlinks to their original location,
67+
// and will enable us to work with symlinked loaders during development.
68+
symlinks: false
69+
},
6570
node: {
6671
// Disable node shims that conflict with NativeScript
6772
"http": false,
@@ -105,17 +110,10 @@ function getRules() {
105110
// Root stylesheet gets extracted with bundled dependencies
106111
{
107112
test: new RegExp(mainSheet),
108-
use: ExtractTextPlugin.extract([
109-
{
110-
loader: "resolve-url-loader",
111-
options: { silent: true },
112-
},
113-
{
114-
loader: "nativescript-css-loader",
115-
options: { minimize: false }
116-
},
117-
"nativescript-dev-webpack/platform-css-loader",
118-
]),
113+
use: [{
114+
loader: "css-loader?url=false",
115+
options: { url: false }
116+
}],
119117
},
120118
// Other CSS files get bundled using the raw loader
121119
{
@@ -153,8 +151,6 @@ function getRules() {
153151

154152
function getPlugins(platform, env) {
155153
let plugins = [
156-
new ExtractTextPlugin(mainSheet),
157-
158154
// Vendor libs go to the vendor.js chunk
159155
new webpack.optimize.CommonsChunkPlugin({
160156
name: ["vendor"],
@@ -167,7 +163,6 @@ function getPlugins(platform, env) {
167163

168164
// Copy assets to out dir. Add your own globs as needed.
169165
new CopyWebpackPlugin([
170-
{ from: mainSheet },
171166
{ from: "css/**" },
172167
{ from: "fonts/**" },
173168
{ from: "**/*.jpg" },
@@ -180,7 +175,7 @@ function getPlugins(platform, env) {
180175
"./vendor",
181176
"./bundle",
182177
]),
183-
178+
184179
// Support for web workers since v3.2
185180
new NativeScriptWorkerPlugin(),
186181

@@ -193,6 +188,14 @@ function getPlugins(platform, env) {
193188
statsFilename: join(__dirname, "report", `stats.json`),
194189
}),
195190

191+
// Setup compiler.inputFileSystem to map files to platform specific files when possible,
192+
// as well as filter ios specific files when building android and the vice-versa.
193+
new PlatformFSPlugin({
194+
platform,
195+
platforms: ["ios", "android"],
196+
ignore: ["App_Resources"]
197+
}),
198+
196199
// Angular AOT compiler
197200
new AotPlugin(
198201
Object.assign({
@@ -201,13 +204,6 @@ function getPlugins(platform, env) {
201204
}, ngToolsWebpackOptions)
202205
),
203206

204-
// Resolve .ios.css and .android.css component stylesheets, and .ios.html and .android component views
205-
new nsWebpack.UrlResolvePlugin({
206-
platform: platform,
207-
resolveStylesUrls: true,
208-
resolveTemplateUrl: true
209-
}),
210-
211207
];
212208

213209
if (env.uglify) {
@@ -223,16 +219,3 @@ function getPlugins(platform, env) {
223219

224220
return plugins;
225221
}
226-
227-
// Resolve platform-specific modules like module.android.js
228-
function getExtensions(platform) {
229-
return Object.freeze([
230-
`.${platform}.ts`,
231-
`.${platform}.js`,
232-
".aot.ts",
233-
".ts",
234-
".js",
235-
".css",
236-
`.${platform}.css`,
237-
]);
238-
}

0 commit comments

Comments
 (0)