From 39352e6e4a07c07da5f60ee3ed7d5b4c2606fc04 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 26 Mar 2018 13:55:50 +0300 Subject: [PATCH] chore: ignore some not-used code from node_modules (-9KB) --- demo/webpack.config.ts | 11 +++++++++++ webpack.config.ts | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/demo/webpack.config.ts b/demo/webpack.config.ts index cb20a3f8..b97b7631 100644 --- a/demo/webpack.config.ts +++ b/demo/webpack.config.ts @@ -78,6 +78,11 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) = performance: false, + externals: { + esprima: 'esprima', + 'node-fetch': 'null', + }, + module: { rules: [ { enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' }, @@ -123,6 +128,12 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) = template: env.playground ? 'demo/playground/index.html' : 'demo/index.html', }), new ForkTsCheckerWebpackPlugin(), + ignore(/js-yaml\/dumper\.js$/), + ignore(/json-schema-ref-parser\/lib\/dereference\.js/), new CopyWebpackPlugin(['demo/openapi.yaml']), ], }); + +function ignore(regexp) { + return new webpack.NormalModuleReplacementPlugin(regexp, require.resolve('lodash/noop.js')); +} diff --git a/webpack.config.ts b/webpack.config.ts index 1be9bfe4..004478a1 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -55,6 +55,7 @@ export default (env: { standalone?: boolean } = {}, { mode }) => ({ : (context, request, callback) => { // ignore node-fetch dep of swagger2openapi as it is not used if (/node-fetch$/i.test(request)) return callback(null, 'var undefined'); + if (/esprima$/i.test(request)) return callback(null, 'var undefined'); return nodeExternals(context, request, callback); }, @@ -124,5 +125,11 @@ export default (env: { standalone?: boolean } = {}, { mode }) => ({ }), new ForkTsCheckerWebpackPlugin({ silent: true }), new webpack.BannerPlugin(BANNER), + ignore(/js-yaml\/dumper\.js$/), + ignore(/json-schema-ref-parser\/lib\/dereference\.js/), ], }); + +function ignore(regexp) { + return new webpack.NormalModuleReplacementPlugin(regexp, require.resolve('lodash/noop.js')); +}