__webpack_require __(...)。确保不是带打字稿的函数

时间:2019-04-11 07:32:17

标签: typescript webpack

我想按需加载模块

我的代码:


interface QeuryInterface {
  [propName : string] : string;
}

interface WebpackRequire extends NodeRequire {
  ensure(
    dependencies: string[],
    callback: (require: WebpackRequire) => void,
    errorCallback?: (error: Error) => void,
    chunkName?: string
  ): void;
};

const qeurystring : string[] = location.search.substring(1).split('&');

const querys : QeuryInterface = {};

qeurystring.forEach(item => {
  const keyval : string[] = item.split('=');
  querys[keyval[0]] = keyval[1];
})

if (querys.device === 'mobile') {
  console.log((require as WebpackRequire));
  (require as WebpackRequire).ensure([], function(require : any) {
    require('./mobile').default;
  })
}

但是我得到一个错误:

__webpack_require__(...).ensure is not a function

它只会出现在打字稿文件中 我该如何运作?

0 个答案:

没有答案