-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
style.js
31 lines (26 loc) · 1.03 KB
/
style.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const path = require('path')
const { dev_server: devServer } = require('../config')
const postcssConfigPath = path.resolve(process.cwd(), '.postcssrc.yml')
const isProduction = process.env.NODE_ENV === 'production'
const extractCSS = !(devServer && devServer.hmr)
const extractOptions = {
fallback: 'style-loader',
use: [
{ loader: 'css-loader', options: { minimize: isProduction } },
{ loader: 'postcss-loader', options: { sourceMap: true, config: { path: postcssConfigPath } } },
'resolve-url-loader',
{ loader: 'sass-loader', options: { sourceMap: true } }
]
}
// For production extract styles to a separate bundle
const extractCSSLoader = {
test: /\.(scss|sass|css)$/i,
use: ExtractTextPlugin.extract(extractOptions)
}
// For hot-reloading use regular loaders
const inlineCSSLoader = {
test: /\.(scss|sass|css)$/i,
use: ['style-loader'].concat(extractOptions.use)
}
module.exports = isProduction || extractCSS ? extractCSSLoader : inlineCSSLoader