Webpack with typescript external commonjs module -


in order code below work, need either repeat require('./rolesservice') clause in rolesview.ts , or uncomment console.log statement. if have neither of lines, webpack not include referenced rolesservice.ts in bundle, resulting in missing rolesserviceprovider error. think know why, since rs not used, except type references disappear once transpiled es5, webpack must optimizing import away. there way not have repeat require('./rolesservice') twice.

rolesview.ts:

"use strict";  import angular = require('angular');  import rs = require('./rolesservice');  require('./rolesservice');  //console.log( rs);  class rolesviewcontroller {     static $inject = ['rolesservice']     constructor(private rolesservice: rs.irolesservice) {         rolesservice.getroles();     } }  angular.module('epsr').component('rolesview', {     template: require('./rolesview.html'),     controller: rolesviewcontroller }); 

rolesservice.ts:

'use strict';  import angular = require('angular');  export interface irole {     id: string;     name: string; }  export interface irolesservice {     getroles(): ng.ipromise<irole[]>; }  class rolesservice implements rolesservice {     static $inject = ['$http'];     constructor(private $http: ng.ihttpservice) {     }      getroles(): ng.ipromise<irole[]> {         return this.$http.get('api/roles');     } }  angular.module('epsr').service('rolesservice', rolesservice); 

i think know why, since rs not used, except type references disappear once transpiled es5, webpack must optimizing import away.

you correct. if type information used typescript strip import.

the available "fixes" are:

  1. what have: require('./rolesservice');
  2. "use" import: rs;

fwiw, angular2 seems solve @inject directive uses import.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -