Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
171 lines (157 loc) · 5.82 KB
/
Copy pathwebpack.config.js
File metadata and controls
171 lines (157 loc) · 5.82 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
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
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 fs = require('fs');
/*
*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_base_path = 'node_modules/@geppettoengine/geppetto-client'
const geppetto_client_path = geppetto_base_path + '/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: path.resolve(__dirname, "static"), to: 'static' });
availableExtensions.push({ from: 'model/*', to: './', flatten: true });
availableExtensions.push({ from: 'images/*', 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") };
console.log("\nThe Webpack entries are:");
console.log(entries);
return {
entry: entries,
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].bundle.js',
publicPath: publicPath
},
plugins: [
/*
* new BundleAnalyzerPlugin({
* analyzerMode: 'static'
* }),
*/
new CopyWebpackPlugin(availableExtensions),
/*
* The page itself. Served as-is (nginx) at <contextPath>/geppetto;
* there is no server-side template step any more.
*/
new HtmlWebpackPlugin({
filename: 'geppetto.html',
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 webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'), } }),
new webpack.IgnorePlugin(/^react-jsonschema-form$/),
new MiniCssExtractPlugin({ filename: '[name].css' })
],
resolve: {
alias: {
root: path.resolve(__dirname),
'@geppettoengine/geppetto-client': path.resolve(__dirname, geppetto_client_path + '/js'),
'@geppettoengine/geppetto-ui': path.resolve(__dirname, geppetto_base_path + '/geppetto-ui/src'),
'@geppettoengine/geppetto-core': path.resolve(__dirname, geppetto_base_path + '/geppetto-core/src'),
geppetto: path.resolve(__dirname, geppetto_client_path, 'js/pages/geppetto/GEPPETTO.js'),
'@geppettoengine/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-transform-runtime", "@babel/plugin-proposal-class-properties"], sourceType: "unambiguous"
}
},
// 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'
},
{
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto"
}
]
},
node: {
fs: 'empty',
child_process: 'empty',
module: 'empty'
}
}
};