diff --git a/types/webpack-virtual-modules/index.d.ts b/types/webpack-virtual-modules/index.d.ts new file mode 100644 index 0000000000..7d465ac02d --- /dev/null +++ b/types/webpack-virtual-modules/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for webpack-virtual-modules 0.1 +// Project: https://github.com/sysgears/webpack-virtual-modules +// Definitions by: Avi Vahl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import webpack = require('webpack'); + +/** + * Plugin that allows dynamic generation of in-memory virtual modules for JavaScript builds + * created with webpack. + */ +declare class VirtualModulesPlugin { + constructor(modules?: Record); + + /** + * Attaches necessary hooks, in particular, `afterEnvironment`, `afterResolvers`, and `watchRun` hooks, + * to ensure that the virtual files are added dynamically. + */ + apply(compiler: webpack.Compiler): void; + + /** + * Writes a static or dynamic virtual module to a path. + */ + writeModule(filePath: string, fileContents: string): void; +} + +export = VirtualModulesPlugin; diff --git a/types/webpack-virtual-modules/tsconfig.json b/types/webpack-virtual-modules/tsconfig.json new file mode 100644 index 0000000000..6c0f89054f --- /dev/null +++ b/types/webpack-virtual-modules/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-virtual-modules-tests.ts" + ] +} diff --git a/types/webpack-virtual-modules/tslint.json b/types/webpack-virtual-modules/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-virtual-modules/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-virtual-modules/webpack-virtual-modules-tests.ts b/types/webpack-virtual-modules/webpack-virtual-modules-tests.ts new file mode 100644 index 0000000000..49110fa026 --- /dev/null +++ b/types/webpack-virtual-modules/webpack-virtual-modules-tests.ts @@ -0,0 +1,13 @@ +import webpack = require('webpack'); +import VirtualModulesPlugin = require('webpack-virtual-modules'); + +const virtualModules = new VirtualModulesPlugin({ + 'node_modules/module-foo.js': 'module.exports = { foo: "foo" };', + 'node_modules/module-bar.js': 'module.exports = { bar: "bar" };', +}); + +virtualModules.writeModule('node_modules/module-foo.js', 'module.exports = { foo: "foo" };'); + +webpack({ + plugins: [virtualModules], +});