forked from vercel/next-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-loader-config.js
61 lines (54 loc) · 1.46 KB
/
css-loader-config.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const findUp = require('find-up')
module.exports = (
config,
extractPlugin,
{ cssModules = false, cssLoaderOptions = {}, postcssLoaderOptions = {}, dev, isServer, loaders = [] }
) => {
const postcssConfig = findUp.sync('postcss.config.js', {
cwd: config.context
})
let postcssLoader
if (postcssConfig) {
//Copy the postcss-loader config options first.
postcssOptionsConfig = Object.assign(
{},
postcssLoaderOptions.config,
{ path: postcssConfig }
)
postcssLoader = {
loader: 'postcss-loader',
options: Object.assign(
{},
postcssLoaderOptions,
{ config: postcssOptionsConfig }
)
}
}
const cssLoader = {
loader: isServer ? 'css-loader/locals' : 'css-loader',
options: Object.assign(
{},
{
modules: cssModules,
minimize: !dev,
sourceMap: dev,
importLoaders: loaders.length + (postcssLoader ? 1 : 0)
},
cssLoaderOptions
)
}
// When not using css modules we don't transpile on the server
if (isServer && !cssLoader.options.modules) {
return ['ignore-loader']
}
// When on the server and using css modules we transpile the css
if (isServer && cssLoader.options.modules) {
return [cssLoader, postcssLoader, ...loaders].filter(Boolean)
}
return [
dev && 'extracted-loader',
...extractPlugin.extract({
use: [cssLoader, postcssLoader, ...loaders].filter(Boolean)
})
].filter(Boolean)
}