-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49022f2
commit 88ff79c
Showing
10 changed files
with
133 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin') | ||
const path = require('path') | ||
const { dev_server: devServer } = require('../config') | ||
const styleRuleFactory = require('./style_rule_factory') | ||
|
||
const postcssConfigPath = path.resolve(process.cwd(), '.postcssrc.yml') | ||
const isProduction = process.env.NODE_ENV === 'production' | ||
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server')) | ||
const isHMR = inDevServer && (devServer && devServer.hmr) | ||
const extractCSS = !(isHMR) || isProduction | ||
|
||
const styleLoader = { | ||
loader: 'style-loader', | ||
options: { | ||
hmr: isHMR, | ||
sourceMap: true | ||
} | ||
} | ||
|
||
const extractOptions = { | ||
fallback: styleLoader, | ||
use: [ | ||
{ loader: 'css-loader', options: { minimize: isProduction, sourceMap: true, importLoaders: 2 } }, | ||
{ loader: 'postcss-loader', options: { sourceMap: true, config: { path: postcssConfigPath } } } | ||
] | ||
} | ||
|
||
// For production extract styles to a separate bundle | ||
const extractCSSLoader = { | ||
test: /\.(css)$/i, | ||
use: ExtractTextPlugin.extract(extractOptions) | ||
} | ||
|
||
// For hot-reloading use regular loaders | ||
const inlineCSSLoader = { | ||
test: /\.(css)$/i, | ||
use: [styleLoader].concat(extractOptions.use) | ||
} | ||
|
||
module.exports = extractCSS ? extractCSSLoader : inlineCSSLoader | ||
module.exports = styleRuleFactory( | ||
/\.(css)$/i, | ||
false, | ||
[] | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const styleRuleFactory = require('./style_rule_factory') | ||
|
||
module.exports = styleRuleFactory( | ||
/\.(css)$/i, | ||
true, | ||
[] | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const styleRuleFactory = require('./style_rule_factory') | ||
|
||
module.exports = styleRuleFactory( | ||
/\.(scss|sass)$/i, | ||
true, | ||
[{ | ||
loader: 'sass-loader', | ||
options: { sourceMap: true } | ||
}] | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
const cssLoader = require('./css') | ||
const deepMerge = require('../utils/deep_merge') | ||
const styleRuleFactory = require('./style_rule_factory') | ||
|
||
// Duplicate and remove css loader object reference | ||
let sassLoader = JSON.parse(JSON.stringify(cssLoader)) | ||
|
||
sassLoader = deepMerge(sassLoader, { | ||
test: /\.(scss|sass)$/i, | ||
use: [{ | ||
module.exports = styleRuleFactory( | ||
/\.(scss|sass)$/i, | ||
false, | ||
[{ | ||
loader: 'sass-loader', | ||
options: { sourceMap: true } | ||
}] | ||
}) | ||
|
||
module.exports = sassLoader | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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 inDevServer = process.argv.find(v => v.includes('webpack-dev-server')) | ||
const isHMR = inDevServer && (devServer && devServer.hmr) | ||
const extractCSS = !(isHMR) || isProduction | ||
|
||
const styleRuleFactory = (test, modules, preprocessors) => { | ||
const styleLoader = { | ||
loader: 'style-loader', | ||
options: { | ||
hmr: isHMR, | ||
sourceMap: true | ||
} | ||
} | ||
|
||
const extractOptions = { | ||
fallback: styleLoader, | ||
use: [ | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
minimize: isProduction, sourceMap: true, importLoaders: 2, modules | ||
} | ||
}, | ||
{ | ||
loader: 'postcss-loader', | ||
options: { | ||
sourceMap: true, config: { path: postcssConfigPath } | ||
} | ||
}, | ||
...preprocessors | ||
] | ||
} | ||
|
||
const modulesCondition = modules | ||
? { include: /\.module\.[a-z]+$/ } | ||
: { exclude: /\.module\.[a-z]+$/ } | ||
|
||
// For production extract styles to a separate bundle | ||
const extractCSSLoader = Object.assign( | ||
{}, | ||
{ test, use: ExtractTextPlugin.extract(extractOptions) }, | ||
modulesCondition | ||
) | ||
|
||
// For hot-reloading use regular loaders | ||
const inlineCSSLoader = Object.assign( | ||
{}, | ||
{ test, use: [styleLoader].concat(extractOptions.use) }, | ||
modulesCondition | ||
) | ||
|
||
return extractCSS ? extractCSSLoader : inlineCSSLoader | ||
} | ||
|
||
module.exports = styleRuleFactory |
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