mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 00:18:20 +08:00
Update externals definition for Webpack V4 (#29345)
* Update externals definition for Webpack V4 - Externals should accept objects as their values (see https://webpack.js.org/configuration/externals/\#object); * fix linting errors * update types, add additional test
This commit is contained in:
committed by
John Reilly
parent
56073ea2ff
commit
f0456f741e
3
types/webpack/index.d.ts
vendored
3
types/webpack/index.d.ts
vendored
@@ -13,6 +13,7 @@
|
||||
// Christophe Hurpeau <https://github.com/christophehurpeau>
|
||||
// ZSkycat <https://github.com/ZSkycat>
|
||||
// John Reilly <https://github.com/johnnyreilly>
|
||||
// Ryan Waskiewicz <https://github.com/rwaskiewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -350,7 +351,7 @@ declare namespace webpack {
|
||||
type ExternalsElement = string | RegExp | ExternalsObjectElement | ExternalsFunctionElement;
|
||||
|
||||
interface ExternalsObjectElement {
|
||||
[key: string]: boolean | string;
|
||||
[key: string]: boolean | string | string[] | Record<string, string | string[]>;
|
||||
}
|
||||
|
||||
type ExternalsFunctionElement = (context: any, request: any, callback: (error: any, result: any) => void) => any;
|
||||
|
||||
@@ -79,6 +79,91 @@ configuration = {
|
||||
}))
|
||||
};
|
||||
|
||||
//
|
||||
// https://webpack.js.org/configuration/externals/
|
||||
//
|
||||
configuration = {
|
||||
externals : {
|
||||
react: 'react'
|
||||
},
|
||||
};
|
||||
|
||||
configuration = {
|
||||
externals : {
|
||||
lodash : {
|
||||
commonjs: 'lodash',
|
||||
amd: 'lodash',
|
||||
root: '_' // indicates global variable
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
configuration = {
|
||||
externals : {
|
||||
subtract : {
|
||||
root: ['math', 'subtract']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
configuration = {
|
||||
externals: [
|
||||
// Disable TSLint for allowing non-arrow functions
|
||||
/* tslint:disable-next-line */
|
||||
function(context, request, callback) {
|
||||
if (/^yourregex$/.test(request)) {
|
||||
// Disable TSLint for bypassing 'no-void-expression' to align with Webpack documentation
|
||||
/* tslint:disable-next-line */
|
||||
return callback(null, 'commonjs ' + request);
|
||||
}
|
||||
callback({}, {});
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
configuration = {
|
||||
externals: [
|
||||
{
|
||||
// String
|
||||
react: 'react',
|
||||
// Object
|
||||
lodash : {
|
||||
commonjs: 'lodash',
|
||||
amd: 'lodash',
|
||||
root: '_' // indicates global variable
|
||||
},
|
||||
// Array
|
||||
subtract: ['./math', 'subtract']
|
||||
},
|
||||
// Disable TSLint for allowing non-arrow functions
|
||||
/* tslint:disable-next-line */
|
||||
function(context, request, callback) {
|
||||
if (/^yourregex$/.test(request)) {
|
||||
// Disable TSLint for bypassing 'no-void-expression' to align with Webpack documentation
|
||||
/* tslint:disable-next-line */
|
||||
return callback(null, 'commonjs ' + request);
|
||||
}
|
||||
callback({}, {});
|
||||
},
|
||||
// Regex
|
||||
/^(jquery|\$)$/i
|
||||
]
|
||||
};
|
||||
|
||||
configuration = {
|
||||
externals: [
|
||||
"add",
|
||||
{
|
||||
subtract: {
|
||||
root: "subtract",
|
||||
commonjs2: "./subtract",
|
||||
commonjs: ["./math", "subtract"],
|
||||
amd: "subtract"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
//
|
||||
// https://webpack.github.io/docs/optimization.html
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user