Skip to content

Commit

Permalink
Extract css rules into one main css file (only for prod env)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalbennani committed Sep 28, 2017
1 parent dc9da73 commit b6cd66a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
47 changes: 32 additions & 15 deletions packages/react-scripts/config/botifyConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const postCssOptions = {
// Necessary for external CSS imports to work
Expand All @@ -20,21 +21,37 @@ const postCssOptions = {
],
};

module.exports = {
babelPresets: [require.resolve('babel-preset-stage-0')],
babelPlugins: [require.resolve('babel-plugin-transform-decorators-legacy')],
webpackLoaders: [
const getSCSSLoaderConfig = isDev => {
const loaders = [
{
test: /\.scss$/,
loaders: [
require.resolve('style-loader'),
require.resolve('css-loader'),
{
loader: require.resolve('postcss-loader'),
options: postCssOptions,
},
require.resolve('sass-loader'),
],
loader: require.resolve('css-loader'),
options: Object.assign({}, { minimize: !isDev }, { importLoaders: 1 }),
},
],
{
loader: require.resolve('postcss-loader'),
options: postCssOptions,
},
require.resolve('sass-loader'),
];

if (isDev) {
return {
test: /\.scss$/,
use: [require.resolve('style-loader'), ...loaders],
};
}

return {
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: require.resolve('style-loader'),
use: loaders,
}),
};
};

module.exports = (isDev = true) => ({
babelPresets: [require.resolve('babel-preset-stage-0')],
babelPlugins: [require.resolve('babel-plugin-transform-decorators-legacy')],
webpackLoaders: [getSCSSLoaderConfig(isDev)],
});
4 changes: 2 additions & 2 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const getClientEnvironment = require('./env');
const paths = require('./paths');
const botifyConfig = require('./botifyConfig');

const getBotifyConfig = require('./botifyConfig');
const botifyConfig = getBotifyConfig();
// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
Expand Down
3 changes: 2 additions & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const paths = require('./paths');
const getClientEnvironment = require('./env');
const botifyConfig = require('./botifyConfig');
const getBotifyConfig = require('./botifyConfig');
const botifyConfig = getBotifyConfig(false);

// Webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
Expand Down

0 comments on commit b6cd66a

Please sign in to comment.