Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible filtering of build output via the Webpack plugin #935

Closed
jeffposnick opened this issue Oct 19, 2017 · 4 comments
Closed

Flexible filtering of build output via the Webpack plugin #935

jeffposnick opened this issue Oct 19, 2017 · 4 comments

Comments

@jeffposnick
Copy link
Contributor

Adapted from @anilanar's comment at #808 (comment):

I guess source-maps can be filtered out by default. However I'm not sure how that would affect development experience when testing offline caching. Need to test it.

This problem is similar to how loaders handle file inclusion/exclusion using three properties: {test, include, exclude} and the code for that is in https://github.com/webpack/webpack/blob/master/lib/ModuleFilenameHelpers.js, look for matchObject. That's what uglifyjs-webpack-plugin is also using in https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/src/index.js.

BTW the same can be used to filter chunks, that would allow a unified API for all kind of filtering and webpack users know how to use {test, include, exclude}.

@jeffposnick
Copy link
Contributor Author

Additional comments from @goldhand:

So considering we filter both chunkname and filename what should the api look like?

We could provide explicit chunk / filename filtering eg:

WorkboxPlugin({
  ...
  filterChunks: {
    test: /\.js($|\?)/i,
  },
  filterFilenames: {
    exclude: /\/excludes/,
  },
});

Or we can just filter both using the same properties, eg:

WorkboxPlugin({
  ...
  test: /\.js($|\?)/i,
  exclude: /\/excludes/,
});

and just filter both chunknames and filenames by those provided values?

Something else to consider is html-webpack-plugin's config the {chunks, excludeChunks} options are very nice. Maybe use those and apply the {test, include, exclude} options only to filenames (chunknames are handled by the chunks option...

@jeffposnick jeffposnick changed the title Default to filtering out Webpack build artifacts Flexible filtering of build output via the Webpack plugin Oct 22, 2017
@goldhand
Copy link
Collaborator

Also need to be able to filter by file size based on the maximumFileSizeToCacheInBytes config option. Webpack assets have a size property so this should be pretty straight forward.

@jeffposnick
Copy link
Contributor Author

FYI, I've asked https://stackoverflow.com/questions/47658134 about whether it's possible/advisable to infer some sort of "how was this asset created/named" data from inside the plugin, as I think that would help a lot when it came to safely answering the "should this be versioned/cached?" question by default.

We'd still want to allow folks to override those default decisions, though.

@jeffposnick jeffposnick self-assigned this Jan 3, 2018
@jeffposnick
Copy link
Contributor Author

FYI, I'm going to put together a PR that follows the {test, include, exclude} convention, using https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/src/index.js. as a model.

This would just filter filenames, and apply after chunks are filtered. (includeChunks and excludeChunks will stick around for that purpose.)

This might not end up being the final implementation, but it seems like it's the most "webpack-y" way of doing things, and I'd like to move this forward and iterate as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants