Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Is it possible to dynamically configure the WebPack configuration (e.g. to do Tree Shaking)? #158
This is a Question
How can I tell webpack to do some Tree Shaking? When I import modules, I might not want the whole thing, but just a function, usually I would just execute webpack in production mode with the -p option, but doesn't seem there is a way to do this here.
It is important that you enable production builds using the manual approach and define a separate webpack config file that includes the production stuff (see webpack.dev.js and webpack.prod.js in webpack's documentation).
Now the trick is, that you select a different webpack configuration file for different stages deployed with Serverless in your
This will use
Now you can put everything that is needed for production builds into your production configuration file.
Maybe it is even possible to create some logic within one configuration file and detect which stage is run by Serverless. But that would need some investigation first.
We could expose the current serverless service configuration (aka serverless.service) into the webpack configuration. Since 2.1.0 the plugin exposes a lib module which would be the perfect target to fetch dynamic deployment information.
So it would be something like this:
This would open the door to access many things that might be of importance and allow a dynamic webpack configuration.