How to remove .js suffix from Angular import
I want to remove .js suffix from Angular import.
Not required (now workable): import { Example } from './whatever/example.js';
Required: import { Example } from './whatever/example';
I suspect I am missing a configuration in 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);
+3
source to share
1 answer
Try adding this to packages:
'.': {
defaultJSExtensions: 'js'
}
Thus, the packages now look like this:
// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
defaultJSExtensions: 'js'
},
app: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
+3
source to share