Skip to content

Support Tree shaking of CSS #506

Open
@ankurp

Description

@ankurp

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Webpack 2 support tree shaking and removal of dead code but this does not work for CSS. If we have a javascript file which exports different CSS files and we only import some of then, then css loader does not tree shake and remove the unused CSS.

Example if we had the code below, css-loader currently is including CSS for both Checkbox and Button but it should only include code for Checkbox since Button is never imported:

// componentcss.js
export const Checkbox = require('./Checkbox.css');
export const Button = require('./Button.css');

// index.js
import { Checkbox } from './componentcss';

What is the expected behavior?

css-loader should tree shake and remove unused CSS import when used webpack 2 with tree shaking feature.

If this is a feature request, what is motivation or use case for changing the behavior?

This will help out reduce the CSS bundle size out of box when using webpack 2

Please mention other relevant information such as your webpack version, Node.js version and Operating System.

This will work with webpack 2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions