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

Question: deny extract css from entry js #527

Closed
slince opened this issue Feb 21, 2019 · 5 comments
Closed

Question: deny extract css from entry js #527

slince opened this issue Feb 21, 2019 · 5 comments

Comments

@slince
Copy link

slince commented Feb 21, 2019

Hello , i dont want to encore extract css into a separate file,Is this possible?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Feb 21, 2019

Hi @slince,

Could you explain a bit more what you are trying to achieve ?
Do you want Webpack to add <style> tags instead ? Or maybe use CSS modules?

@slince
Copy link
Author

slince commented Feb 21, 2019

@Lyrkan Yes, i just want webpack add style tag. Because css is very simple, it is not necessary to send an http request to download it.

@Lyrkan
Copy link
Collaborator

Lyrkan commented Feb 21, 2019

I see, so you'd need to replace the mini-css-extract-plugin loader by the style-loader.

The bad news is: there is nothing built in the current version of Encore to do that... it may become a bit easier when #509 is released.

However you should be able to do it manually:

// webpack.config.js
const Encore = require('@symfony/webpack-encore');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

Encore
  // (...)
;

// Retrieve the generated config
const config = Encore.getWebpackConfig();

// Replace the mini-css-extract-plugin loader by style-loader
for (const rule of config.module.rules) {
  if (rule.use && rule.use[0] === MiniCssExtractPlugin.loader) {
    rule.use[0] = 'style-loader';
  }
}

// Make sure you export `config` and not
// `Encore.getWebpackConfig()` here
module.exports = config;

@Kocal
Copy link
Contributor

Kocal commented Feb 21, 2019

(I can't wait for #509 to be released 👀)

@slince
Copy link
Author

slince commented Mar 1, 2019

TKS

@slince slince closed this as completed Mar 1, 2019
weaverryan added a commit that referenced this issue Mar 25, 2019
…kan)

This PR was merged into the master branch.

Discussion
----------

Add Encore.disableCssExtraction() to the public API

This PR adds an `Encore.disableCssExtraction()` method that allows to disable the `mini-css-extract-plugin` and use the `style-loader` instead.

It can be used to solve various problems that, until now, required a really ugly workaround that relied on our internal implementation (for instance the following commit probably broke some builds that used previous versions of it: 6867443#diff-8beacd21a12ca072bafa4e8e3f1aae6b).

Related issues: #3, #256, #348, #527

Commits
-------

347feed Add Encore.disableCssExtraction() to the public API
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

No branches or pull requests

3 participants