mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
81 lines
1.7 KiB
TypeScript
81 lines
1.7 KiB
TypeScript
/// <reference path="./webpack-env.d.ts" />
|
|
|
|
interface SomeModule {
|
|
someMethod(): void;
|
|
}
|
|
|
|
let someModule = require<SomeModule>('./someModule');
|
|
someModule.someMethod();
|
|
|
|
let context = require.context('./somePath', true);
|
|
let contextModule = context<SomeModule>('./someModule');
|
|
|
|
require(['./someModule', './otherModule'], (someModule: SomeModule, otherModule: any) => {
|
|
|
|
});
|
|
|
|
// check if HMR is enabled
|
|
if(module.hot) {
|
|
// accept update of dependency
|
|
module.hot.accept("./handler.js", function() {
|
|
//...
|
|
});
|
|
}
|
|
|
|
module.exports = null;
|
|
|
|
// check if HMR is enabled
|
|
if(module.hot) {
|
|
|
|
// accept itself
|
|
module.hot.accept();
|
|
|
|
// dispose handler
|
|
module.hot.dispose(function() {
|
|
// revoke the side effect
|
|
//...
|
|
});
|
|
}
|
|
|
|
class ModuleData {
|
|
updated: boolean;
|
|
}
|
|
|
|
if (module.hot) {
|
|
module.hot.accept((err: Error) => {
|
|
//...
|
|
});
|
|
|
|
module.hot.decline("./someModule");
|
|
|
|
module.hot.dispose((data: ModuleData) => {
|
|
data.updated = true;
|
|
// ...
|
|
});
|
|
|
|
let disposeHandler: ((data: ModuleData) => void) = data => {
|
|
// ...
|
|
};
|
|
module.hot.addDisposeHandler(disposeHandler);
|
|
module.hot.removeDisposeHandler(disposeHandler);
|
|
|
|
module.hot.check(true, (err: Error, outdatedModules: (string|number)[]) => {
|
|
// ...
|
|
});
|
|
|
|
module.hot.apply({ ignoreUnaccepted: true }, (err: Error, outdatedModules: (string|number)[]) => {
|
|
// ...
|
|
});
|
|
|
|
var status: string = module.hot.status();
|
|
let statusHandler: ((status: string) => void) = status => {
|
|
// ...
|
|
};
|
|
module.hot.status(statusHandler);
|
|
module.hot.addStatusHandler(statusHandler);
|
|
module.hot.removeStatusHandler(statusHandler);
|
|
}
|
|
|
|
|
|
|