Skip to content

stats include less-loader, css-loader #17

Closed

Description

@garthk

The visualiser output for our project attributes a substantial proportion of our bundle to less-loader and css-loader. Their names do not appear in the bundle.

We're using webpack to handle our LESS, so webpack.json includes…

const config = validate({
    entry: [
        './src/client/styles.less',
        './src/client/index.tsx',
    ],
//...
    plugins: [
        new ExtractTextPlugin('dist/static/assets/styles.css'),
    ],
    module: {
        loaders: [
            { test: /\.json$/, loader: 'json-loader' },
            { test: /\.tsx?$/, loader: 'ts-loader' },
            { test: /\.less$/,
              loader: ExtractTextPlugin.extract("style-loader", "css-loader!postcss-loader!less-loader")
            },
            { test: /\.css$/,
              loader: ExtractTextPlugin.extract("style-loader", "css-loader!postcss-loader")

The visualiser output shows a substantial part of our bundle occupied by less-loader and css-loader despite their names not appearing anywhere in the bundle.

stats.json contains:

  "modules": [
    {
...
    },
    {
      "id": 1,
      "identifier": "~/src/project/node_modules/less-loader/stringify.loader.js!~/src/project/node_modules/bootstrap/less/mixins/text-emphasis.less",
      "name": "./~/less-loader/stringify.loader.js!./~/bootstrap/less/mixins/text-emphasis.less",
...
      "issuer": "~/src/project/node_modules/css-loader/index.js!~/src/project/node_modules/postcss-loader/index.js!~/src/project/node_modules/less-loader/index.js!~/src/project/src/client/styles.less",
...
      "reasons": [
        {
          "moduleId": 48,
          "moduleIdentifier": "~/src/project/node_modules/css-loader/index.js!~/src/project/node_modules/postcss-loader/index.js!~/src/project/node_modules/less-loader/index.js!~/src/project/src/client/styles.less",
          "module": "./~/css-loader!./~/postcss-loader!./~/less-loader!./src/client/styles.less",
          "moduleName": "./~/css-loader!./~/postcss-loader!./~/less-loader!./src/client/styles.less",
          "type": "loader",
          "userRequest": "-!~/src/project/node_modules/less-loader/stringify.loader.js!~/src/project/node_modules/bootstrap/less/mixins/text-emphasis.less"
        }

Any tips on how to follow the reasons back to the root cause?

Activity

  1. blikblum commented on Dec 10, 2016

    @blikblum
    Contributor

    Same thing here.
    The less-loader/css-loader output is effectively stripped from bundle by the ExtractTextPlugin

    But stats.json still show them. Maybe an issue in the generation of json output? (i.e., using --json argument)

    An possible workaround is to check the issuer field since it has the following pattern when is extracted from bundle:

    \\node_modules\\extract-text-webpack-plugin\\loader.js?{\"remove\":true}

  2. motin commented on Jan 9, 2017

    @motin

    @chrisbateman It seems less-loader is still affected (not seeing css-loader though) https://www.dropbox.com/s/9on4hjfafdjy9zv/Screenshot%202017-01-09%2014.40.25.png?dl=0
    Using v 0.1.7 which was released 15 hours ago.

  3. chrisbateman commented on Jan 9, 2017

    @chrisbateman
    Owner

    @motin So right now I believe we're only removing CSS if it uses the ExtractTextPlugin - which moves the CSS to a separate file. Otherwise, the CSS is still included in your JS bundle.

  4. motin commented on Jan 9, 2017

    @motin

    @chrisbateman ExtractTextPlugin is used in our config, and the CSS is placed in a separate file because of to that. The screenshot however shows that "less-loader" still is included, even though it is only a dev-dependency in our project.

  5. chrisbateman commented on Jan 9, 2017

    @chrisbateman
    Owner

    @motin Hmm, I don't think I'm seeing that in my test app.

    Any chance you could share your loader config and maybe even your stats.json?

  6. blikblum commented on Jan 9, 2017

    @blikblum
    Contributor

    I analyzed the stats of one of my projects, see below

    Stats: https://1drv.ms/u/s!AhehaflTFeyS9CR_UiVT6Z7CVxaG
    https://github.com/blikblum/marionette-wires-revisited/blob/master/src/main.js

    All css is required by 'main.less' and extracted into a separate file (checked the actual bundle to make sure).

    Tracking main.less entries in stats log i got the following:

    • main.less entry as id 212 with name as "./src/main.less"
      extract-text-plugin is in identifier path, but NOT in issuer
      index !== null
      "chunks": [0]

    • second main.less entry as id 213 with name as ".//css-loader!.//less-loader!./src/main.less"
      extract-text-plugin is NOT in identifier path, but is in issuer
      index !== null
      "chunks": []

    later comes all *.less files required by main.less, the first being wells.less with the following pattern

    • name: "./~ /less-loader/stringify.loader.js!./~/bootstrap/less/[name of the less file]"
      extract-text-plugin is NOT in identifier path and is NOT in issuer
      index: null
      "chunks": []

    With this i modified the buildHierarchy to account these situations. Will do a PR to be reviewed

  7. chrisbateman commented on Jan 11, 2017

    @chrisbateman
    Owner

    @blikblum Awesome. I think it maybe it wasn't showing up in my example since none of my less files were in the node_modules. Thanks very much!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions