forked from mendixlabs/calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
126 lines (121 loc) · 4 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
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const package = require("./package");
const widgetName = package.widgetName;
const name = package.widgetName.toLowerCase();
const packageName = process.env.npm_package_name;
const mxHost = process.env.npm_package_config_mendixHost || "http://localhost:8080";
const developmentPort = process.env.npm_package_config_developmentPort || "3000";
const widgetConfig = {
entry: `./src/components/${widgetName}Container.ts`,
output: {
path: path.resolve(__dirname, "dist/tmp"),
filename: `widgets/com/mendix/widget/custom/${name}/${widgetName}.js`,
libraryTarget: "umd",
},
devServer: {
port: developmentPort,
proxy: [ {
target: mxHost,
context: [ "**", `!/widgets/com/mendix/widget/custom/${name}/${widgetName}.js` ],
onError: function(err, req, res) {
if (res && res.writeHead) {
res.writeHead(500, {
"Content-Type": "text/plain"
});
if (err.code === "ECONNREFUSED") {
res.end("Please make sure that the Mendix server is running at " + mxHost
+ " or change the configuration \n "
+ "> npm config set " + packageName + ":mendixhost http://host:port");
} else {
res.end("Error connecting to Mendix server"
+ "\n " + JSON.stringify(err, null, 2));
}
}
}
} ],
stats: "errors-only"
},
resolve: {
extensions: [ ".ts", ".js" ],
alias: {
"tests": path.resolve(__dirname, "./tests")
}
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true
}
}
},
{
test: /\.jsx?$/,
include: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
presets: ["@babel/preset-env"]
}
}
},
{ test: /\.(css|scss)$/, use: [
"style-loader", "css-loader", "sass-loader"
] },
]
},
mode: "development",
devtool: "source-map",
externals: [ "react", "react-dom" ],
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CopyWebpackPlugin(
[ {
from: "src/**/*.xml",
toType: "template",
to: "widgets/[name].[ext]"
} ],
{ copyUnmodified: true }
),
new webpack.LoaderOptionsPlugin({ debug: true })
]
};
const previewConfig = {
entry: `./src/${widgetName}.webmodeler.ts`,
output: {
path: path.resolve(__dirname, "dist/tmp"),
filename: `widgets/${widgetName}.webmodeler.js`,
libraryTarget: "commonjs"
},
resolve: {
extensions: [ ".ts", ".js" ]
},
module: {
rules: [
{ test: /\.ts$/, loader: "ts-loader", options: {
compilerOptions: {
"module": "CommonJS",
}
}},
{ test: /\.css$/, use: "raw-loader" },
{
test: /\.scss$/, use: [
{ loader: "raw-loader" },
{ loader: "sass-loader" }
]
}
]
},
mode: "development",
externals: [ "react", "react-dom" ],
plugins: [ new webpack.LoaderOptionsPlugin({ debug: true }) ]
};
module.exports = [ widgetConfig, previewConfig ];