Olezt
Olezt

Reputation: 1738

How to remove .js suffix from Angular imports

I want to remove .js suffix from Angular imports.

Not wanted (now workable): import { Example } from './whatever/example.js';

Wanted: import { Example } from './whatever/example';

I suspect I am missing a configuration in the systemjs.config.js.

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': '/node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      // other libraries

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

Upvotes: 3

Views: 180

Answers (1)

Nate
Nate

Reputation: 6474

Try adding this in packages:

'.': {
    defaultJSExtensions: 'js'
}

Such that packages now looks like:

// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
    defaultJSExtensions: 'js'
},
app: {
    defaultExtension: 'js'
},
rxjs: {
    defaultExtension: 'js'
    }
}

Upvotes: 3

Related Questions