Skip to content
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,27 @@ class Encore {
return this;
}

/**
* Configure the style-loader.
*
* https://github.com/webpack-contrib/style-loader#Options
*
* ```
* Encore.configureStyleLoader(function(config) {
* // change the config
* // config.injectType = 'styleTag';
* });
* ```
*
* @param {function} callback
* @returns {Encore}
*/
configureStyleLoader(callback) {
webpackConfig.configureStyleLoader(callback);

return this;
}

/**
* If enabled, the react preset is added to Babel.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class WebpackConfig {
this.babelConfigurationCallback = () => {};
this.babelPresetEnvOptionsCallback = () => {};
this.cssLoaderConfigurationCallback = () => {};
this.styleLoaderConfigurationCallback = () => {};
this.splitChunksConfigurationCallback = () => {};
this.watchOptionsConfigurationCallback = () => {};
this.devServerOptionsConfigurationCallback = () => {};
Expand Down Expand Up @@ -468,6 +469,14 @@ class WebpackConfig {
this.cssLoaderConfigurationCallback = callback;
}

configureStyleLoader(callback) {
if (typeof callback !== 'function') {
throw new Error('Argument 1 to configureStyleLoader() must be a callback function.');
}

this.styleLoaderConfigurationCallback = callback;
}

enableSingleRuntimeChunk() {
this.shouldUseSingleRuntimeChunk = true;
}
Expand Down
11 changes: 8 additions & 3 deletions lib/loaders/css-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const applyOptionsCallback = require('../utils/apply-options-callback');

module.exports = {
/**
Expand All @@ -22,13 +23,17 @@ module.exports = {
*/
prependLoaders(webpackConfig, loaders) {
if (!webpackConfig.extractCss) {

const options = {
sourceMap: webpackConfig.useSourceMaps,
};

// If the CSS extraction is disabled, use the
// style-loader instead.
return [{
loader: 'style-loader',
options: {
sourceMap: webpackConfig.useSourceMaps,
}
options: applyOptionsCallback(webpackConfig.styleLoaderConfigurationCallback, options)

}, ...loaders];
}

Expand Down