-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgatsby-node.js
96 lines (89 loc) · 2.9 KB
/
gatsby-node.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
90
91
92
93
94
95
96
var nib = require("nib");
var jeet = require("jeet");
var rupture = require("rupture");
var path = require("path");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpack = require("webpack");
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ncp = require('ncp').ncp;
ncp.limit = 16;
exports.modifyWebpackConfig = function(config, env) {
var IS_STATIC = env === 'build-html' || env === 'build-css';
// console.log(config._config.entry);
// var entry = config._config.entry.main;
var publicPath = config._config.output.publicPath;
// var output = config._config.output;
// output.filename = "[name].js";
// config._config.entry = {
// main: entry,
// };
config.merge({
stylus: {
use: [jeet(), nib(), rupture()],
import: [
'~nib/lib/nib/index.styl',
'~jeet/stylus/jeet/_jeet.styl'
]
},
output: {
// filename: "[name].js",
publicPath: "/",
},
resolveLoader: {
root: path.join(__dirname, "node_modules"),
modulesDirectories: ['./'],
},
resolve: {
root: path.join(__dirname, "node_modules"),
alias: {
// 'original-react': path.join(__dirname, "node_modules", "react"),
// 'react/lib': path.join(__dirname, "node_modules", "react", "lib"),
// 'react': path.join(__dirname, 'patched-react.js'),
'pypyjs': '../playground/graphene-js/pypyjs',
'playground-page': (env == "build-html")?'../pages/_empty':'../playground/page',
'playground-wrapper': (env == "develop")?'../playground/page':'../playground/wrapper',
},
modulesDirectories: ['./']
}
});
if (IS_STATIC) {
config.plugin('extract-css', ExtractTextPlugin, ["app.css"]);
}
config.plugin('static', CopyWebpackPlugin, [[{ from: './static/**/*'}]]);
config.plugin('define-env', webpack.DefinePlugin, [{
"ENV": JSON.stringify(env),
"process.env.BROWSER": JSON.stringify(true),
"PUBLIC_PATH": JSON.stringify(publicPath),
}]);
// if (env != "static") {
// config.plugin('commons', webpack.optimize.CommonsChunkPlugin, ["commons.js"]);
// }
config.loader('stylus', function(cfg) {
cfg.test = /\.styl$/;
if (IS_STATIC) {
cfg.loader = ExtractTextPlugin.extract('style-loader', 'css-loader!stylus-loader', { allChunks: true });
}
else {
cfg.loader = 'style-loader!css-loader!stylus-loader';
}
return cfg
});
// config.removeLoader('png');
// config.loader('png', function(cfg) {
// cfg.test = /\.png$/;
// cfg.loader = 'url-loader'
// return cfg
// })
return config;
};
exports.postBuild = function(pages, callback) {
var srcPath = path.join(__dirname, "static/"); //current folder
var destPath = path.join(__dirname, "public"); //Any destination folder
console.log('Copying files...');
ncp(srcPath, destPath, function (err) {
if (err) {
return console.error(err);
}
callback();
});
};