This repository has been archived by the owner on Sep 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.js
78 lines (66 loc) · 2.32 KB
/
index.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
var path = require('path');
var WriteFilePlugin = require('write-file-webpack-plugin');
// helper function to get the base url for theme assets
// if no explicit value is set, we'll try to use the theme directory
function getProductionBaseUrl(api, pluginOptions) {
var baseUrl = pluginOptions.baseUrl;
if (typeof baseUrl !== 'undefined') {
return baseUrl.endsWith('/') ? baseUrl : baseUrl + '/';
}
return '/' + api.resolve('assets').split('/').slice(-3).join('/') + '/';
}
// helper function for resolving configuration
// returns undefined if object does not have property
function resolveProperty(obj, p) {
return p.split('.').reduce(function(p, k) {
return p && p[k];
}, obj);
}
module.exports = (api, options) => {
var isProduction = process.env.NODE_ENV === 'production';
var pluginOptions = resolveProperty(options, 'pluginOptions.vuetober') || {
baseUrl: undefined,
};
// configure the dev server and public path based on environment
options.devServer = {
disableHostCheck: true,
public: 'http://localhost:8080',
};
options.publicPath = isProduction
? getProductionBaseUrl(api, pluginOptions)
: 'http://localhost:8080/';
// set webpack's output directory to /assets
options.outputDir = 'assets';
// save our only page to /pages
api.chainWebpack(function(config) {
config.plugin('html').tap(function(args) {
Object.assign(args[0], {
minify: Object.assign((args[0].minify || {}), {
// comments will always need to be removed to preserve october's
// theme configuration and php section at the top of the file.
removeComments: true,
}),
filename: '../pages/index.htm',
template: 'src/index.htm',
});
return args;
});
});
//
// non-production
//
if (!isProduction) {
api.configureWebpack(function(config) {
return {
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
},
},
plugins: [
new WriteFilePlugin({ test: /\.htm$/ }),
],
};
});
}
}