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

Style-loader duplicates insert function #518

Closed
HuHguZ opened this issue Jul 7, 2021 · 3 comments · Fixed by #521
Closed

Style-loader duplicates insert function #518

HuHguZ opened this issue Jul 7, 2021 · 3 comments · Fixed by #521

Comments

@HuHguZ
Copy link

HuHguZ commented Jul 7, 2021

  • Operating System: linux mint 20
  • Node Version: v14.16.0
  • NPM Version: 6.14.11
  • webpack Version: 5.28.0
  • css-loader Version: 3.0.0

Expected Behavior

I expect that the style-loader will add the insert function to the bundle exactly 1 time.

Actual Behavior

But in reality, this function is created for each css file and inserted as an expression, webpack cannot optimize it, because it thinks that these are different functions

image

Code

//css part of module.rules productuion config
{
    test: /\.css$/,
    exclude: /\.page\.css$/,
    use: [
      {
        loader: 'style-loader',
        options: {
          injectType: 'singletonStyleTag',
          insert: [Function: _insertCssIntoIframeImportedByStyleLoader]
        }
      },
      'css-modules-typescript-loader'
    ]
  },
  {
    test: /\.page\.css$/,
    use: [ 'style-loader', 'css-modules-typescript-loader' ]
  },
  {
    test: /\.css$/,
    use: [
      {
        loader: 'css-loader',
        options: {
          importLoaders: 1,
          modules: { localIdentName: '[hash:base64:5]' }
        }
      },
      'postcss-loader'
    ]
  }
@alexander-akait
Copy link
Member

Partial fixed here #520, anyway it is impossible to use custom function and include this only once, but we have solution { insert: require.resolve('./my-custom-style-function') }, so you will not have multiple functions, WIP on this

@alexander-akait
Copy link
Member

Fixed #521, note you need to use insert: require.resolve('./path/to/insert.js') to allow reduce size of runtime

@HuHguZ
Copy link
Author

HuHguZ commented Jul 16, 2021

thanks

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

Successfully merging a pull request may close this issue.

2 participants