-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
194 lines (181 loc) · 6.5 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
/*
*var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
* <%=htmlWebpackPlugin.options.GEPPETTO_CONFIGURATION._webapp_folder%>
*/
var geppettoConfig;
try {
geppettoConfig = require('./GeppettoConfiguration.json');
console.log('\nLoaded Geppetto config from file');
} catch (e) {
// Failed to load config file
console.error('\nFailed to load Geppetto Configuration')
}
var geppetto_client_path = 'node_modules/@geppettoengine/geppetto-client'
var publicPath = path.join("/", geppettoConfig.contextPath, "geppetto/build/");
console.log("\nThe public path (used by the main bundle when including split bundles) is: " + publicPath);
var isProduction = process.argv.indexOf('-p') >= 0;
console.log("\n Building for a " + ((isProduction) ? "production" : "development") + " environment")
var availableExtensions = [];
availableExtensions.push({ from: path.resolve(__dirname, geppetto_client_path, "static/*"), to: 'static', flatten: true });
availableExtensions.push({ from: 'tutorials/*', to: './', flatten: true });
availableExtensions.push({ from: 'model/*', to: './', flatten: true });
console.log(availableExtensions);
module.exports = function (env){
// geppettoConfig._webapp_folder
if (env != undefined){
console.log(env);
if (env.contextPath){
geppettoConfig.contextPath = env.contextPath;
}
if (env.useSsl){
geppettoConfig.useSsl = JSON.parse(env.useSsl);
}
if (env.noTest){
geppettoConfig.noTest = JSON.parse(env.noTest);
}
if (env.embedded){
geppettoConfig.embedded = JSON.parse(env.embedded);
}
if (env.embedderURL){
geppettoConfig.embedderURL = env.embedderURL;
}
}
console.log('Geppetto configuration \n');
console.log(JSON.stringify(geppettoConfig, null, 2), '\n');
var entries = {
main: path.resolve(__dirname, "Main.js"),
admin: path.resolve(__dirname, geppetto_client_path, "js/pages/admin/admin.js"),
};
console.log("\nThe Webpack entries are:");
console.log(entries);
return {
entry: entries,
optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: 'common',
minChunks: 2, // Minimum # of chunks which need to contain a module before it's moved into the commons chunk.
chunks: 'initial', // initial, async or all
reuseExistingChunk: true, // use existing chunk if available instead of creating new one
enforce: true // form this chunk irrespective of the size of the chunk
}
}
}
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].bundle.js',
publicPath: publicPath
},
plugins: [
/*
* new BundleAnalyzerPlugin({
* analyzerMode: 'static'
* }),
*/
new CopyWebpackPlugin(availableExtensions),
new HtmlWebpackPlugin({
filename: 'geppetto.vm',
template: path.resolve(__dirname, geppetto_client_path, 'js/pages/geppetto/geppetto.ejs'),
GEPPETTO_CONFIGURATION: geppettoConfig,
/*
* chunks: ['main'] Not specifying the chunk since its not possible
* yet (need to go to Webpack2) to specify UTF-8 as charset without
* which we have errors
*/
chunks: []
}),
new HtmlWebpackPlugin({
filename: 'admin.vm',
template: path.resolve(__dirname, geppetto_client_path, 'js/pages/admin/admin.ejs'),
GEPPETTO_CONFIGURATION: geppettoConfig,
/*
* chunks: ['admin'] Not specifying the chunk since its not possible
* yet (need to go to Webpack2) to specify UTF-8 as charset without
* which we have errors
*/
chunks: []
}),
new HtmlWebpackPlugin({
filename: 'dashboard.vm',
template: path.resolve(__dirname, geppetto_client_path, 'js/pages/dashboard/dashboard.ejs'),
GEPPETTO_CONFIGURATION: geppettoConfig,
chunks: []
}),
new HtmlWebpackPlugin({
filename: '../WEB-INF/web.xml',
template: path.resolve(__dirname, 'WEB-INF/web.ejs'),
GEPPETTO_CONFIGURATION: geppettoConfig,
chunks: []
}),
new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'), } }),
new MiniCssExtractPlugin({ filename: '[name].css' })
],
resolve: {
alias: {
root: path.resolve(__dirname),
'geppetto-client': path.resolve(__dirname, geppetto_client_path),
geppetto: path.resolve(__dirname, geppetto_client_path, 'js/pages/geppetto/GEPPETTO.js'),
'geppetto-client-initialization': path.resolve(__dirname, geppetto_client_path, 'js/pages/geppetto/main'),
handlebars: 'handlebars/dist/handlebars.js'
},
extensions: ['*', '.js', '.json', '.ts', '.tsx', '.jsx'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [/ami.min.js/, /node_modules\/(?!(@geppettoengine\/geppetto-client)\/).*/],
loader: 'babel-loader',
query: {
presets: [['@babel/preset-env', { "modules": false }], '@babel/preset-react'],
plugins: [ "@babel/plugin-proposal-class-properties" ]
}
},
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
},
{
test: /Dockerfile/,
loader: 'ignore-loader'
},
{
test: /\.(py|jpeg|svg|gif|css|jpg|md|hbs|dcm|gz|xmi|dzi|sh|obj|yml|nii)$/,
loader: 'ignore-loader'
},
{
test: /\.(png|eot|ttf|woff|woff2|svg)(\?[a-z0-9=.]+)?$/,
loader: 'url-loader?limit=100000'
},
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader" }
]
},
{
test: /\.less$/,
loader: 'style-loader!css-loader!less-loader?{"modifyVars":{"url":"\'' + path.resolve(__dirname, geppettoConfig.themes) + '\'"}}'
},
{
test: /\.html$/,
loader: 'raw-loader'
}
]
},
node: {
fs: 'empty',
child_process: 'empty',
module: 'empty'
}
}
};