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

Commit 5c00f2d

Browse files
committed
feat(deps): add support for webpack 2.2+
Add NodeGlobalsPlugin to prevent webpack from overriding the global property.
1 parent 79286a6 commit 5c00f2d

5 files changed

+25
-5
lines changed

Diff for: installer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ exports.removeNpmScripts = removeNpmScripts;
106106

107107
function getProjectDependencies() {
108108
var dependencies = {
109-
"webpack": "~2.1.0-beta.27",
109+
"webpack": "2.2.0",
110110
"webpack-sources": "~0.1.3",
111111
"copy-webpack-plugin": "~3.0.1",
112112
"raw-loader": "~0.5.1",
@@ -116,8 +116,8 @@ function getProjectDependencies() {
116116
};
117117

118118
if (isAngular) {
119-
dependencies["@angular/compiler-cli"] = "2.4.3";
120-
dependencies["@ngtools/webpack"] = "1.2.1";
119+
dependencies["@angular/compiler-cli"] = "~2.4.3";
120+
dependencies["@ngtools/webpack"] = "1.2.4";
121121
dependencies["typescript"] = "^2.0.10";
122122
dependencies["htmlparser2"] = "~3.9.2";
123123
} else {

Diff for: nativescript-target/NsNodeGlobalsPlugin.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// HACK: Prevent webpack from replacing "global"
2+
// Fixes StackOverflow error caused by DefinePlugin with webpack 2.2+
3+
4+
var ConstDependency = require("webpack/lib/dependencies/ConstDependency");
5+
6+
function NsNodeGlobalsPlugin() {}
7+
NsNodeGlobalsPlugin.prototype.apply = function(compiler) {
8+
compiler.plugin("compilation", function(compilation, params) {
9+
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
10+
parser.plugin("expression global", function(expr) {
11+
var dep = new ConstDependency("global", expr.range);
12+
dep.loc = expr.loc;
13+
this.state.current.addDependency(dep);
14+
return true;
15+
});
16+
});
17+
});
18+
};
19+
20+
module.exports = NsNodeGlobalsPlugin;

Diff for: nativescript-target/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = function nativescriptTarget(compiler) {
22
var options = this;
33
var webpackLib = "webpack/lib";
44

5+
var NsNodeGlobalsPlugin = require("./NsNodeGlobalsPlugin");
56
// Custom template plugin
67
var NsJsonpTemplatePlugin = require("./NsJsonpTemplatePlugin");
78

@@ -10,6 +11,7 @@ module.exports = function nativescriptTarget(compiler) {
1011
var LoaderTargetPlugin = require(webpackLib + "/LoaderTargetPlugin");
1112

1213
compiler.apply(
14+
new NsNodeGlobalsPlugin(),
1315
new NsJsonpTemplatePlugin(options.output),
1416
new FunctionModulePlugin(options.output),
1517
new NodeSourcePlugin(options.node),

Diff for: webpack.common.js.angular.template

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = function (platform, destinationApp) {
2727
}),
2828
//Define useful constants like TNS_WEBPACK
2929
new webpack.DefinePlugin({
30-
global: "global",
3130
__dirname: "__dirname",
3231
"global.TNS_WEBPACK": "true",
3332
}),

Diff for: webpack.common.js.nativescript.template

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module.exports = function (platform, destinationApp) {
2626
}),
2727
//Define useful constants like TNS_WEBPACK
2828
new webpack.DefinePlugin({
29-
global: "global",
3029
__dirname: "__dirname",
3130
"global.TNS_WEBPACK": "true",
3231
}),

0 commit comments

Comments
 (0)