-
-
Save leonid-bauxy/22d70a5257e850bc1ecd68e390b62de0 to your computer and use it in GitHub Desktop.
./helpers/getStylesLoaders.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { join } from 'path'; | |
import _ from 'lodash'; | |
import postCssScss from 'postcss-scss'; | |
import { SASS_GLOBALS_PATH } from '../constants'; | |
import ifCondition from './ifCondition'; | |
import getEnvHelpers from './getEnvHelpers'; | |
/** | |
* @param {Object} [options={}] | |
* @param {boolean} [cssModules=false] | |
* @param {boolean} [preRender=false] if `true`, only extract selectors as json, instead of generating `css` | |
* @param {boolean} [postCssPack='defaults'] | |
* @returns {Object[]} | |
*/ | |
export default function getStylesLoaders({ cssModules = false, preRender = false, postCssPack = 'defaults' } = {}) { | |
const { isProd, ifNotTest } = getEnvHelpers(); | |
const ifCssModules = ifCondition(cssModules); | |
const ifNotPreRender = ifCondition(!preRender); | |
return _.compact([ | |
ifNotPreRender({ | |
loader: 'style', | |
}), | |
{ | |
loader: preRender ? 'css/locals' : 'css', | |
query: { | |
...ifCssModules({ | |
modules: true, | |
importLoaders: 4, | |
localIdentName: '[local]--[hash:base64:10]', | |
}), | |
minimize: false, | |
sourceMap: !isProd, | |
}, | |
}, | |
ifNotTest({ | |
loader: 'postcss', | |
query: { | |
syntax: postCssScss, | |
parser: postCssScss, | |
pack: postCssPack, | |
sourceMap: !isProd, | |
}, | |
}), | |
{ | |
loader: 'resolve-url', | |
query: { | |
sourceMap: !isProd, | |
}, | |
}, | |
{ | |
loader: 'sass', | |
query: { | |
outputStyle: 'expanded', | |
sourceMap: !isProd, | |
}, | |
}, | |
{ | |
loader: join(__dirname, '../webpackLoaders/injectGlobalStyles.js'), | |
query: { | |
path: SASS_GLOBALS_PATH, | |
}, | |
}, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment