您需要创建一个“systemjs.config.js”文件并从index.html加载它,就像常规脚本一样:
<script src="systemjs.config.js"></script>
确保在配置脚本之前还包含 System.JS:
<script src="node_modules/systemjs/dist/system.src.js"></script>
以下脚本加载第一个模块:
System.import('app').catch(function (err) { console.error(err); });
默认情况下(根据您的 systemjs.config.js),SystemJS 将查找 app.js 或 app/main.js。
在 systemjs.config.js 文件中,您希望将节点包映射到存在 index.js 或 package.json 的路径,该路径指示模块所在的位置。该模块应该与您打算使用的模块加载器兼容:AMD、UMD、CommonJS、SystemJS、es6 等
以下内容应该在您的 systemjs.config.js 文件中起作用:
'paths': {
'npm:':'node_modules/'
},
'map': {
'ng2-datetime-picker': 'npm:ng2-datetime-picker'
...
},
'packages': {
'ng2-datetime-picker': 'dist/ng2-datetime-picker.umd.js'
}
或者,您可以直接映射 UMD 文件:
'paths': {
'npm:':'node_modules/'
},
'map': {
'ng2-datetime-picker': 'npm:ng2-datetime-picker/dist/ng2-datetime-picker.umd.js'
...
}
以下内容仅适用于 CommonJS/AMD/SystemJS,因为 index.js 使用“require”语法:
'paths': {
'npm:':'node_modules/'
},
'map': {
'ng2-datetime-picker': 'npm:ng2-datetime-picker'
...
},
'packages': {
'ng2-datetime-picker': 'dist/index.js'
}
EDIT
这应该有效:
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: { main: 'boot.js', defaultExtension: 'js' },
rxjs: { defaultExtension: 'js' },
'ng2-datetime-picker': { main: 'dist/ng2-datetime-picker.umd.js', defaultExtension: 'js' }
}