-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathwebpack.config.js
114 lines (89 loc) · 2.79 KB
/
webpack.config.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict';
// Libs
const Path = require('path');
const Webpack = require('webpack');
const ChildProcess = require('child_process');
const FileSystem = require('fs');
// Parameters
const IS_WATCHING = Array.isArray(process.argv) && process.argv.indexOf('--watch') > -1;
const TMP_PATH = Path.join(__dirname, 'tmp');
const PLUGINS_PATH = Path.join(__dirname, 'plugins');
const PUBLIC_PATH = Path.join(__dirname, 'public');
const PUBLIC_JS_PATH = Path.join(PUBLIC_PATH, 'js');
const PUBLIC_CSS_PATH = Path.join(PUBLIC_PATH, 'css');
/**
* Gets all .js entries
*/
function getJsEntries() {
// Include main codebase files
let entry = {
dashboard: './src/Client/dashboard.js',
environment: './src/Client/environment.js',
utilities: './src/Common/utilities',
controller: './src/Client/Controller',
service: './src/Client/Service',
entity: './src/Client/Entity'
}
// Include plugins
FileSystem.writeFileSync(Path.join(PUBLIC_JS_PATH, 'plugins.js'), '/* No plugins installed */');
let pluginScripts = [];
if(FileSystem.existsSync(PLUGINS_PATH)) {
for(let plugin of FileSystem.readdirSync(PLUGINS_PATH)) {
let scriptPath = Path.join(PLUGINS_PATH, plugin, 'src', 'Client', 'index.js');
if(!FileSystem.existsSync(scriptPath)) { continue; }
pluginScripts.push(scriptPath);
}
}
if(pluginScripts.length > 0) {
entry.plugins = pluginScripts;
}
return entry;
}
/**
* Runs the SASS compilation
* NOTE: We're using NPX because of how dependency heavy it is to do via WebPack
*/
function compileCss() {
// Build SASS commands
let sassArgs = [
'sass',
'--source-map',
'--embed-sources',
];
if(IS_WATCHING) {
sassArgs.push('--watch');
sassArgs.push('--poll');
}
sassArgs.push('./style/index.scss:./public/css/style.css');
// Start SASS compilation
let cmd = ChildProcess.spawn('npx', sassArgs);
cmd.stdout.on('data', (data) => {
console.log('\n' + data.toString('utf8'));
});
cmd.stderr.on('data', (data) => {
console.log(data.toString('utf8'));
});
cmd.on('close', (code) => {
if(code == 0) { return; }
console.log('SASS compilation exited with status code', code);
});
}
// Compile CSS
compileCss();
// Export settings
module.exports = {
mode: 'none',
devtool: 'source-map',
// Input .js
entry: getJsEntries(),
// Output .js
output: {
path: Path.resolve(__dirname, 'public/js'),
filename: '[name].js'
},
// Automatically accept these extensions
resolve: {
modules: [Path.resolve(__dirname), Path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.json']
}
};