如何从 Angular 导入中删除 .js 后缀
How to remove .js suffix from Angular imports
我想从 Angular 导入中删除 .js 后缀。
不需要(现在可用): import { Example } from './whatever/example.js';
求职: import { Example } from './whatever/example';
我怀疑我缺少 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);
尝试在包中添加:
'.': {
defaultJSExtensions: 'js'
}
这样的包现在看起来像:
// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
defaultJSExtensions: 'js'
},
app: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
我想从 Angular 导入中删除 .js 后缀。
不需要(现在可用): import { Example } from './whatever/example.js';
求职: import { Example } from './whatever/example';
我怀疑我缺少 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);
尝试在包中添加:
'.': {
defaultJSExtensions: 'js'
}
这样的包现在看起来像:
// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
defaultJSExtensions: 'js'
},
app: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}