-
Notifications
You must be signed in to change notification settings - Fork 47
/
webpack.atlasmaker-tools.config.js
78 lines (73 loc) · 2.06 KB
/
webpack.atlasmaker-tools.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
/* eslint-disable prefer-exponentiation-operator */
const fs = require('fs');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const glob = require('glob');
// list tools with user interface
const uilist = glob.sync('./view/atlasmaker/src/tools/*/index.js');
const uientries = {};
for (const item of uilist) {
const arr = item.split('/');
const key = arr[arr.length - 2]; // module name is directory's name
uientries[key] = item;
}
// list tools without user interface
const cmdlist = glob.sync('./view/atlasmaker/src/tools/*.js');
const cmdentries = {};
for (const item of cmdlist) {
const arr = item.split('/');
const key = arr[arr.length - 1].split('.').slice(0, -1)
.join('.'); // module name is script's name
cmdentries[key] = item;
}
// write
const dir = path.resolve(__dirname, 'view/atlasmaker/dist/atlasmaker-tools/');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(
path.resolve(__dirname, 'view/atlasmaker/dist/atlasmaker-tools/tools.json'),
JSON.stringify([
...Object.keys(uientries).map((name) => ({ name, type: 'ui' })),
...Object.keys(cmdentries).map((name) => ({ name, type: 'cmd' }))
])
);
// combine both lists
const entries = {};
Object.keys(uientries).forEach((k) => { entries[k] = uientries[k]; });
Object.keys(cmdentries).forEach((k) => { entries[k] = cmdentries[k]; });
console.log('entries:', entries);
module.exports = {
mode: 'production',
entry: entries,
devtool: 'eval-source-map',
plugins: [new CleanWebpackPlugin(['dist'])],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'view/atlasmaker/dist/atlasmaker-tools')
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { esModule: false } }
]
},
{
test: /\.(svg)$/,
use: {
loader: 'url-loader',
options: {
noquotes: true
}
}
},
{
test: /\.(html)$/,
use: ['html-loader']
}
]
}
};