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

Commit

Permalink
feat: add webpack4 support (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
SvetoslavTsenov authored and sis0k0 committed Apr 27, 2018
1 parent 8fd544b commit eefce39
Show file tree
Hide file tree
Showing 32 changed files with 697 additions and 617 deletions.
14 changes: 14 additions & 0 deletions android-app-components-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function(source) {
this.cacheable();
const { modules } = this.query;
const imports = modules.map(m => `require("${m}");`).join("\n");
const augmentedSource = `
if (!global["__snapshot"]) {
${imports}
}
${source}
`;

this.callback(null, augmentedSource);
};
5 changes: 0 additions & 5 deletions demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ test-results.xml
tsconfig.aot.json

vendor.js
vendor-platform.android.js
vendor-platform.ios.js

vendor.ts
vendor-platform.android.ts
vendor-platform.ios.ts

webpack.config.js
41 changes: 22 additions & 19 deletions demo/AngularApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
}
},
"dependencies": {
"@angular/common": "~5.2.0",
"@angular/compiler": "~5.2.0",
"@angular/core": "~5.2.0",
"@angular/forms": "~5.2.0",
"@angular/http": "~5.2.0",
"@angular/platform-browser": "~5.2.0",
"@angular/platform-browser-dynamic": "~5.2.0",
"@angular/router": "~5.2.0",
"nativescript-angular": "next",
"@angular/common": "~6.0.0-rc.0",
"@angular/compiler": "~6.0.0-rc.0",
"@angular/core": "~6.0.0-rc.0",
"@angular/forms": "~6.0.0-rc.0",
"@angular/http": "~6.0.0-rc.0",
"@angular/platform-browser": "~6.0.0-rc.0",
"@angular/platform-browser-dynamic": "~6.0.0-rc.0",
"@angular/router": "~6.0.0-rc.0",
"nativescript-angular": "rc",
"nativescript-theme-core": "~1.0.2",
"reflect-metadata": "~0.1.8",
"rxjs": "^5.5.0",
"rxjs": "~6.0.0-beta.1",
"tns-core-modules": "next",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "~5.2.0",
"@ngtools/webpack": "~1.9.4",
"@angular-devkit/core": "~0.5.5",
"@angular/compiler-cli": "~6.0.0-rc.0",
"@ngtools/webpack": "~6.0.0-rc.3",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
Expand All @@ -39,7 +40,8 @@
"babylon": "6.18.0",
"chai": "~4.1.1",
"chai-as-promised": "~7.1.1",
"copy-webpack-plugin": "~4.3.0",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
Expand All @@ -51,14 +53,15 @@
"nativescript-dev-typescript": "next",
"nativescript-dev-webpack": "file:../..",
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"sass-loader": "^6.0.6",
"typescript": "~2.6.2",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"typescript": "~2.7.2",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
18 changes: 12 additions & 6 deletions demo/JavaScriptApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
"tns-core-modules": "next"
},
"devDependencies": {
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"copy-webpack-plugin": "~4.0.1",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
Expand All @@ -33,11 +37,13 @@
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"sass-loader": "^6.0.6",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
20 changes: 11 additions & 9 deletions demo/TypeScriptApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
"tns-core-modules": "next"
},
"devDependencies": {
"awesome-typescript-loader": "~3.1.3",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
"awesome-typescript-loader": "~5.0.0-1",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"copy-webpack-plugin": "~4.0.1",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
Expand All @@ -36,14 +37,15 @@
"nativescript-dev-typescript": "next",
"nativescript-dev-webpack": "file:../..",
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.2",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"sass-loader": "^6.0.6",
"typescript": "~2.6.2",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"typescript": "~2.7.2",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
14 changes: 8 additions & 6 deletions dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,28 @@ function addDependency(deps, name, version, force) {

function getRequiredDeps(packageJson) {
const deps = {
"webpack": "~3.10.0",
"webpack": "~4.5.0",
"webpack-cli": "~2.0.14",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "~1.1.0",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.3.0",
"copy-webpack-plugin": "~4.5.1",
"raw-loader": "~0.5.1",
"css-loader": "~0.28.7",
"nativescript-worker-loader": "~0.8.1",
"resolve-url-loader": "~2.2.1",
"resolve-url-loader": "~2.3.0",
"extract-text-webpack-plugin": "~3.0.2",
"uglifyjs-webpack-plugin": "~1.1.6",
"uglifyjs-webpack-plugin": "~1.2.4",
};

if (isAngular({packageJson})) {
Object.assign(deps, {
"@angular/compiler-cli": packageJson.dependencies["@angular/core"],
"@ngtools/webpack": "~1.9.4",
"@ngtools/webpack": "~6.0.0-rc.3",
"@angular-devkit/core": "~0.5.5",
});
} else if (isTypeScript({packageJson})) {
Object.assign(deps, { "awesome-typescript-loader": "~3.1.3" });
Object.assign(deps, { "awesome-typescript-loader": "~5.0.0" });
}

if (isSass({packageJson})) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function buildEnvData($projectData, platform, env) {
const appResourcesPath = getAppResourcesPathFromProjectData($projectData);
Object.assign(envData,
appPath && { appPath },
appResourcesPath && { appResourcesPath }
appResourcesPath && { appResourcesPath },
);

return envData;
Expand Down
68 changes: 41 additions & 27 deletions nativescript-target/NsJsonpChunkTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var ConcatSource = require("webpack-sources").ConcatSource;
var Template = require("webpack/lib/Template");
"use strict";

function JsonpChunkTemplatePlugin() { }
module.exports = JsonpChunkTemplatePlugin;

JsonpChunkTemplatePlugin.prototype.apply = function (chunkTemplate) {
const ConcatSource = require("webpack-sources").ConcatSource;

//JSONP version
chunkTemplate.plugin("render", function (modules, chunk) {
var jsonpFunction = this.outputOptions.jsonpFunction;
var source = new ConcatSource();
source.add(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ",");
source.add(modules);
var entries = [chunk.entryModule].filter(Boolean).map(function (m) {
return m.id;
class JsonpChunkTemplatePlugin {
apply(chunkTemplate) {
chunkTemplate.hooks.render.tap(
"JsonpChunkTemplatePlugin",
(modules, chunk) => {
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
const globalObject = chunkTemplate.outputOptions.globalObject;
const source = new ConcatSource();
source.add(
`(${globalObject}[${JSON.stringify(jsonpFunction)}] = ${
globalObject
}[${JSON.stringify(jsonpFunction)}] || []).push([${JSON.stringify(
chunk.ids
)},`
);
source.add(modules);
const entries = [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
if (entries.length > 0) {
source.add(`,${JSON.stringify(entries)}`);
}
source.add("])");
return source;
}
);
chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => {
hash.update("JsonpChunkTemplatePlugin");
hash.update("4");
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
});
if (entries.length > 0) {
source.add("," + JSON.stringify(entries));
}
source.add(")");
return source;
});
chunkTemplate.plugin("hash", function (hash) {
hash.update("JsonpChunkTemplatePlugin");
hash.update("3");
hash.update(this.outputOptions.jsonpFunction + "");
hash.update(this.outputOptions.library + "");
});
};
}
}
module.exports = JsonpChunkTemplatePlugin;

27 changes: 0 additions & 27 deletions nativescript-target/NsJsonpHotUpdateChunkTemplatePlugin.js

This file was deleted.

Loading

0 comments on commit eefce39

Please sign in to comment.