This repository has been archived by the owner on Aug 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
89 lines (79 loc) · 1.93 KB
/
build.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
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
var metalsmith = require('metalsmith')
var collections = require('metalsmith-collections')
var fingerprint = require('metalsmith-fingerprint-ignore')
var postcss = require('metalsmith-postcss')
var serve = require('metalsmith-serve')
var watch = require('metalsmith-watch')
var patterns = require('css-patterns')
var config = require('./lib/plugins/config')
var meta = require('./lib/plugins/meta')
var pug = require('./lib/plugins/pug')
var robots = require('./lib/plugins/robots')
var sass = require('./lib/plugins/sass')
var msmith = metalsmith(__dirname)
var watchmode = process.argv[2] === '-w'
var production =
process.env.NODE_ENV === 'staging' ||
process.env.NODE_ENV === 'production'
msmith.destination('public')
msmith.ignore([
'includes/**/*',
'layouts/**/*',
'mixins/**/*',
'**/.*',
'**/_*.pug'
])
msmith.use(config(process.env.NODE_ENV, watchmode))
msmith.use(meta())
msmith.use(robots())
if (production) {
msmith.use(fingerprint({
pattern: [
'**/*.!(pug|scss)',
'!favicon.ico',
'!robots.txt'
]
}))
}
msmith.use(sass({
outputDir: 'css',
outputStyle: production ? 'compressed' : 'expanded',
sourceMap: !production,
sourceMapContents: !production,
sourceMapEmbed: !production,
includePaths: patterns.includePaths
}))
msmith.use(postcss([
require('autoprefixer'),
require('postcss-focus')
]))
if (production) msmith.use(fingerprint({ pattern: ['**/*.css'] }))
msmith.use(collections({
posts: {
pattern: 'blog/!(index).pug',
reverse: true,
sortBy: 'date'
}
}))
msmith.use(pug({
pretty: true,
useMetadata: true
}))
if (watchmode) {
msmith.use(watch({
paths: {
'config/**/*': '**/*',
'src/**/*.pug': '**/*.pug',
'src/**/*.scss': 'scss/index.scss',
'src/**/*.!(pug|scss)': true
},
livereload: true
}))
msmith.use(serve({
host: '0.0.0.0',
port: process.env.PORT || 8000
}))
}
msmith.build(function (err) {
if (err) throw err
})