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

refactor: Refactor moduleId: __filename to moduleId: module.id #337

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/AngularApp/app/item/item-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ItemService } from "./item.service";

@Component({
selector: "ns-details",
moduleId: __filename,
moduleId: module.id,
templateUrl: "./item-detail.component.html",
})
export class ItemDetailComponent implements OnInit {
Expand Down
4 changes: 2 additions & 2 deletions demo/AngularApp/app/item/items.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ItemService } from "./item.service";

@Component({
selector: "ns-items",
moduleId: __filename,
moduleId: module.id,
styleUrls: ["./items.component.scss"],
templateUrl: "./items.component.html",
})
Expand All @@ -19,4 +19,4 @@ export class ItemsComponent implements OnInit {
ngOnInit(): void {
this.items = this.itemService.getItems();
}
}
}
16 changes: 16 additions & 0 deletions moduleid-compat-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* When building NativeScript angular apps without webpack (`tns run android`) the moduleId: module.id is necessary.
* When building with webpack the angular compiler and webpack handle relative paths in the modules and no longer need moduleId
* to be set, however webpack emits numbers for module.id and angular has typecheck for moduleId to be a string.
*/
module.exports = function (source, map) {
this.cacheable();

// Strips occurences of `moduleId: module.id,`, since it is no longer needed for webpack builds
const noModuleIdsSource = source.replace(/moduleId\:\s*module\.id\s*(\,)?/g, result =>
// Try to preserve char count so sourcemaps may remain intact
"/*" + result.substring(2, result.length - 2) + "*/"
);

this.callback(null, noModuleIdsSource, map);
};
2 changes: 1 addition & 1 deletion templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = env => {
// SASS support
{ test: /\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
// Compile TypeScript files with ahead-of-time compiler.
{ test: /.ts$/, loader: "@ngtools/webpack" },
{ test: /.ts$/, use: ["nativescript-dev-webpack/moduleid-compat-loader", "@ngtools/webpack"] },
],
},
plugins: [
Expand Down