-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwebpack.config.js
More file actions
112 lines (105 loc) · 2.73 KB
/
webpack.config.js
File metadata and controls
112 lines (105 loc) · 2.73 KB
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
const webpack = require('webpack');
const path = require('path');
const fs = require("fs");
//const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var config = {
resolve: {
extensions: ['.js']
},
plugins: [],
module: {
rules: [
{
test: /\.js$/,
loader: require.resolve('@open-wc/webpack-import-meta-loader')
}
]
}
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.entry = './src/index_core.js';
config.devtool = 'inline-source-map';
config.output = {
filename: 'PennController.js',
path: path.resolve(__dirname, 'dev/js_includes')
};
}
if (argv.mode === 'production') {
config.entry = {
'Components/PennCore': './src/index_core.js',
PennController: './src/index_full.js',
doc: './src/doc.js'
};
config.output = {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
};
fs.readdirSync('./src/elements/').forEach(file => {
let name = 'Components/'+file.replace(/\.[^.]+$/,'');
config.entry[name] = './src/elements/'+file;
});
}
return config;
};
var ACstringAll = "";
var ACstringElement = {};
var ACpattern = new RegExp("/[*] ([$]AC[$] ([^.]+?)\.([^\\s]+?) (.+?) [$]AC[$]) [*]/", "g");
var ACdir = function(dir){
fs.readdirSync(dir).forEach(file => {
file = path.resolve(dir, file);
var stat = fs.statSync(file);
if (stat && stat.isDirectory())
ACdir(file);
else{
var content = fs.readFileSync(file, 'utf8');
var AC;
while ((AC = ACpattern.exec(content)) !== null){
let isElement = file.match(/PennElement_.+\.js/);
if (isElement){
if (!ACstringElement.hasOwnProperty(isElement[0]))
ACstringElement[isElement[0]] = "";
ACstringElement[isElement[0]] += AC[1];
}
else
ACstringAll += AC[1];
}
}
});
}
ACdir('./src/');
// config.plugins.push(
// new webpack.BannerPlugin({
// banner: ACstringAll,
// include: /.*PennCo.*/
// })
// );
config.plugins.push(
new webpack.BannerPlugin({
banner: ACstringAll,
include: /doc/
})
);
// for (let el in ACstringElement){
// config.plugins.push(
// new webpack.BannerPlugin({
// banner: ACstringElement[el],
// include: [new RegExp(".*"+el+".*"), /.*PennController.*/]
// })
// );
// }
for (let el in ACstringElement){
config.plugins.push(
new webpack.BannerPlugin({
banner: ACstringElement[el],
include: /doc/
})
);
}
// Add main banner
config.plugins.push(
new webpack.BannerPlugin({
banner: fs.readFileSync('./src/banner', 'utf8'),
exclude: [/.*PennElement.*/,/doc/]
})
);