Skip to content

Commit

Permalink
chore: ignore some not-used code from node_modules (-9KB)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 26, 2018
1 parent c3c46e1 commit 39352e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions demo/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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'));
}
7 changes: 7 additions & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down Expand Up @@ -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'));
}

0 comments on commit 39352e6

Please sign in to comment.