forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.github-deploy.js
79 lines (69 loc) · 2.5 KB
/
webpack.github-deploy.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
/**
* @author: @AngularClass
*/
const helpers = require('./helpers');
const ghDeploy = require('./github-deploy');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const ghpages = require('gh-pages');
const webpackConfig = ghDeploy.getWebpackConfigModule(); // the settings that are common to prod and dev
/**
* Webpack Constants
*/
const GIT_REMOTE_NAME = 'origin';
const COMMIT_MESSAGE = 'Updates';
const GH_REPO_NAME = ghDeploy.getRepoName(GIT_REMOTE_NAME);
const METADATA = webpackMerge(webpackConfig.metadata, {
/**
* Prefixing the REPO name to the baseUrl for router support.
* This also means all resource URIs (CSS/Images/JS) will have this prefix added by the browser
* unless they are absolute (start with '/'). We will handle it via `output.publicPath`
*/
baseUrl: '/' + GH_REPO_NAME + '/' + ghDeploy.safeUrl(webpackConfig.metadata.baseUrl)
});
module.exports = webpackMerge(webpackConfig, {
/**
* Merged metadata from webpack.common.js for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,
output: {
/**
* The public path is set to the REPO name.
*
* `HtmlElementsPlugin` will add it to all resources url's created by it.
* `HtmlWebpackPlugin` will add it to all webpack bundels/chunks.
*
* In theory publicPath shouldn't be used since the browser should automatically prefix the
* `baseUrl` into all URLs, however this is not the case when the URL is absolute (start with /)
*
* It's important to prefix & suffix the repo name with a slash (/).
* Prefixing so every resource will be absolute (otherwise it will be url.com/repoName/repoName...
* Suffixing since chunks will not do it automatically (testes against about page)
*/
publicPath: '/' + GH_REPO_NAME + '/' + ghDeploy.safeUrl(webpackConfig.output.publicPath)
},
plugins: [
function() {
this.plugin("done", function(stats) {
console.log('Starting deployment to GitHub.');
const logger = function (msg) {
console.log(msg);
};
const options = {
logger: logger,
remote: GIT_REMOTE_NAME,
message: COMMIT_MESSAGE
};
ghpages.publish(webpackConfig.output.path, options, function(err) {
if (err) {
console.log('GitHub deployment done. STATUS: ERROR.');
throw err;
} else {
console.log('GitHub deployment done. STATUS: SUCCESS.');
}
});
})
}
]
});