hhs*_*diq 6 javascript angular
我使用angular2-seed作为我项目的种子.它require在源文件中工作得非常好.但每当我包含一个新库并在index.html中引用它时,就会在控制台中弹出一个require未定义的错误.
Systemjs包括在内
我已经在SO上阅读了以前的答案,建议使用system.js.systemjs已经包含在内.
的index.html
<!-- shims:js -->
<script src="/node_modules/systemjs/dist/system.src.js?1458283463580"></script>
<script src="/node_modules/systemjs/dist/system-polyfills.src.js?1458283463581"></script>
<script src="/node_modules/reflect-metadata/Reflect.js?1458283463582"></script>
<script src="/node_modules/es6-shim/es6-shim.js?1458283463582"></script>
<script src="/node_modules/angular2/bundles/angular2-polyfills.js?1458283463582"></script>
<!-- endinject -->
<script>System.config({"defaultJSExtensions":true,"paths":{"./admin/main":"/./admin/main","angular2/*":"/angular2/*","rxjs/*":"/rxjs/*","*":"/node_modules/*"},"packages":{"angular2":{"defaultExtension":false},"rxjs":{"defaultExtension":false}},"map":{"moment":"moment/moment.js"}})</script>
<!-- libs:js -->
<script src="/node_modules/rxjs/bundles/Rx.js?1458283463585"></script>
<script src="/node_modules/angular2/bundles/angular2.js?1458283463585"></script>
<script src="/node_modules/angular2/bundles/router.js?1458283463585"></script>
<script src="/node_modules/angular2/bundles/http.js?1458283463586"></script>
<script src="/node_modules/ng2-bootstrap/ng2-bootstrap.js?1458283463586"></script>
<script src="/node_modules/ng2-select/ng2-select.js?1458283463586"></script>
<script src="/node_modules/lodash/index.js?1458283463587"></script>
<script src="/node_modules/ng2-pagination/index.js?1458283463587"></script>
<!-- endinject -->
<!-- inject:js -->
<!-- endinject -->
<script>
System.import('./admin/main')
.catch(function (e) {
console.error(e,
'Report this error at https://github.com/punchagency/staffing-client/issues');
});
</script>Run Code Online (Sandbox Code Playgroud)
错误
使用需求的来源
lodash的index.js
module.exports = require('./lodash');
Run Code Online (Sandbox Code Playgroud)
类似地,其他库ng2-select也ng2-bootstrap有类似的错误
您需要在 SystemJS 中配置其他依赖项,而不是将它们直接包含到script标记中。
这是一个示例:
<script>
System.configure({
map: {
'ng2-bootstrap': 'node_modules/ng2-bootstrap',
'ng2-select': 'node_modules/ng2-select',
lodash: 'node_modules/lodash/lodash.js'
},
package: {
(...)
}
});
System.import(...);
</script>
Run Code Online (Sandbox Code Playgroud)
请参阅以下问题了解更多详细信息:
| 归档时间: |
|
| 查看次数: |
5119 次 |
| 最近记录: |