-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
65 lines (60 loc) · 2.35 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
/* eslint no-console: 0 */
const join = require('path').join;
const fs = require('fs');
// SASS
require('node-sass').render(
{ file: join(__dirname, 'src', 'scss', 'main.scss'),
outputStyle: "compressed"
}, function(err, result) {
if(err) console.error(err);
else {
if(!fs.existsSync(join(__dirname, 'public', 'styles'))) fs.mkdirSync(join(__dirname, 'public', 'styles'));
require('postcss')([require('autoprefixer'), require('postcss-url')])
.process(result.css, {
from: join(__dirname, 'src', 'scss', 'main.scss'),
to: join(__dirname, 'public', 'styles', 'main.css')
}).then(function(result) {
fs.writeFile(join(__dirname, 'public', 'styles', 'main.css'), result.css, function(err) {
if (err) console.error(err);
else console.log('Style bundled');
});
});
}
});
// JS
require('webpack')(require('./webpack.config')).run(function(err, stats) {
if (err) console.error(err);
else console.log('Client bundled');
});
if(process.env.NODE_ENV === 'production') {
// Favicons
require('favicons')(
'./public/imgs/logoRed.svg',
{
appName: 'LobsterPages',
path: '/icons'
},
function (err, resp) {
if (err) console.log(err);
else {
fs.writeFile(join(__dirname, 'src', 'faviconsHeader.ejs'), resp.html.join('\n'), function(err) {
if (err) console.log(err);
else console.log('Favicons header written');
});
if(!fs.existsSync(join(__dirname, 'public', 'icons'))) fs.mkdirSync(join(__dirname, 'public', 'icons'));
resp.files.concat(resp.images).forEach(function(item) {
fs.writeFile(join(__dirname, 'public', 'icons', item.name), item.contents, function(err) {
if (err) console.log(err);
else console.log(`Written ${item.name}`);
});
});
}
}
);
// Sitemap
require('babel-register');
new (require('react-router-sitemap').default)(require('./src/js/routes').LobsterRoutes)
.build('http://almighty.lobsters.tech')
.save('./public/sitemap.xml');
console.log('Sitemap generated');
}