FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/tools/compile-css.js at world-cup-2018 · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
tools
/
compile-css.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (91 loc) · 2.91 KB
Breadcrumbs
frontend
/
tools
/
compile-css.js
Copy path
File metadata and controls
108 lines (91 loc) · 2.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// unified CSS creation module. used for prod and dev/watch tasks.
// writes files to `static/target/stylesheets` i.e. has side-effects
// exports a function which takes:
// 1. glob for files in static/src/stylesheets
// 2. options object offering `remify` (boolean) and `browsers` (browserlist)
const
fs
=
require
(
'fs'
)
;
const
path
=
require
(
'path'
)
;
const
mkdirp
=
require
(
'mkdirp'
)
;
const
glob
=
require
(
'glob'
)
;
const
pify
=
require
(
'pify'
)
;
const
sass
=
require
(
'node-sass'
)
;
const
postcss
=
require
(
'postcss'
)
;
const
autoprefixer
=
require
(
'autoprefixer'
)
;
const
pxtorem
=
require
(
'postcss-pxtorem'
)
;
const
sassRenderP
=
pify
(
sass
.
render
)
;
const
writeFileP
=
pify
(
fs
.
writeFile
)
;
const
{
src
,
target
}
=
require
(
'./__tasks__/config'
)
.
paths
;
const
sassDir
=
path
.
resolve
(
src
,
'stylesheets'
)
;
const
SASS_SETTINGS
=
{
outputStyle
:
'compressed'
,
sourceMap
:
true
,
precision
:
5
,
}
;
const
BROWSERS_LIST
=
[
'Firefox >= 26'
,
'Explorer >= 10'
,
'Safari >= 5'
,
'Chrome >= 36'
,
'iOS >= 5'
,
'Android >= 2'
,
'BlackBerry >= 6'
,
'ExplorerMobile >= 7'
,
'> 2% in US'
,
'> 2% in AU'
,
'> 2% in GB'
,
]
;
const
REMIFICATIONS
=
{
replace
:
true
,
root_value
:
16
,
unit_precision
:
5
,
propList
:
[
'*'
]
,
}
;
const
getFiles
=
sassGlob
=>
glob
.
sync
(
path
.
resolve
(
sassDir
,
sassGlob
)
)
;
module
.
exports
=
(
sassGlob
,
{
remify
=
true
,
browsers
=
BROWSERS_LIST
}
=
{
}
)
=>
{
if
(
typeof
sassGlob
!==
'string'
)
{
return
Promise
.
reject
(
new
Error
(
'No glob provided.'
)
)
;
}
return
Promise
.
all
(
getFiles
(
sassGlob
)
.
map
(
filePath
=>
{
const
dest
=
path
.
resolve
(
target
,
'stylesheets'
,
path
.
relative
(
sassDir
,
filePath
)
.
replace
(
'scss'
,
'css'
)
)
;
const
sassOptions
=
Object
.
assign
(
{
file
:
filePath
,
outFile
:
dest
,
sourceMapContents
:
true
,
includePaths
:
[
'node_modules'
]
,
}
,
SASS_SETTINGS
)
;
const
postcssPlugins
=
[
autoprefixer
(
{
browsers
}
)
]
;
if
(
remify
)
{
postcssPlugins
.
push
(
pxtorem
(
REMIFICATIONS
)
)
;
}
mkdirp
.
sync
(
path
.
parse
(
dest
)
.
dir
)
;
return
sassRenderP
(
sassOptions
)
.
then
(
result
=>
postcss
(
postcssPlugins
)
.
process
(
result
.
css
.
toString
(
)
,
{
from
:
filePath
,
to
:
dest
,
map
:
{
inline
:
false
,
prev
:
result
.
map
.
toString
(
)
,
}
,
}
)
)
.
then
(
result
=>
Promise
.
all
(
[
writeFileP
(
dest
,
result
.
css
)
,
writeFileP
(
`
${
dest
}
.map`
,
result
.
map
)
,
]
)
)
;
}
)
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL