我有一个打印文件.ts
以下文件。
我使用的WebPack版本2.2.1
webpack 2.2.1安排错误顺序/位置的依赖关系
import { module } from "angular";
import "typeahead";
class TypeAheadController {
static $inject = ["$log", "$timeout", "$http", "$interpolate"];
constructor(
public $log: ng.ILogService,
public $timeout: ng.ITimeoutService,
public $http: ng.IHttpService,
public $interpolate: ng.IInterpolateService) {
// do stuff with Typeahead/Bloodhound.
var bloodhoundSuggestions = new Bloodhound({
datumTokenizer: _ => Bloodhound.tokenizers.obj.whitespace(_[this.inputValue]),
queryTokenizer: Bloodhound.tokenizers.whitespace,
}
因为预输入定义是@types/typeahead
和实现是typeahead.js
,有必要别名位置webpack.config.js
globule = require("globule");
var configuration = {
context: __dirname,
resolve:
{
alias: {
typeahead: "typeahead.js"
}
},
entry: [
...globule.find("client/*.ts", { srcBase: "wwwroot/js/admin" })
],
output: {
filename: "./wwwroot/js/admin/admin.js"
},
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' }
]
}
};
console.log(configuration);
module.exports = configuration;
不幸的是在结果生成的JavaScript文件,Bloodhound
未定义。
Webpack似乎包括和使用相关的要求(323),但它显然不工作,因为Bloodhound
是未定义的。
在输出文件中,require在控制器定义之前就存在。
Object.defineProperty(exports, "__esModule", { value: true });
var angular_1 = __webpack_require__(16);
__webpack_require__(323);
/**
* initialise and use a type ahead to find suggestions.
*/
var TypeAheadController = (function() {
太多进一步下跌的文件,我发现323
/***/ }),
/* 323 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(setImmediate) {var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
如何解决未定义的警犬?