-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
121 lines (116 loc) · 3.77 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
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const MomentLocalesPlugin = require("moment-locales-webpack-plugin");
const packageConfig = require("./package").config;
const widgetName = packageConfig.widgetName;
const name = packageConfig.widgetName.toLowerCase();
const host = "http://localhost:8080";
const widgetConfig = {
entry: `./src/components/${widgetName}.tsx`,
output: {
path: path.resolve(__dirname, "dist/tmp"),
filename: `widgets/${packageConfig.packagePath}/${name}/${widgetName}.js`,
libraryTarget: "umd"
},
devServer: {
port: 3000,
proxy: [
{
context: ["**", `!/widgets/${packageConfig.packagePath}/${name}/${widgetName}.js`],
target: host,
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 " +
host +
" or change the configuration \n > npm config set transcript-editor:mendixhost http://host:port"
);
} else {
res.end("Error connecting to Mendix server" + "\n " + JSON.stringify(err, null, 2));
}
}
}
}
]
},
resolve: {
extensions: [".ts", ".js", ".tsx"],
alias: {
tests: path.resolve(__dirname, "./tests")
}
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true
}
}
]
},
{
test: /\.(sa|sc|c)ss$/,
use: ["style-loader", "css-loader"]
}
]
},
// devtool: "eval",
mode: "production",
externals: ["react", "react-dom"],
plugins: [
new MomentLocalesPlugin(),
new ForkTsCheckerWebpackPlugin(),
new CopyWebpackPlugin(
[
{
from: "src/**/*.xml",
toType: "template",
to: "widgets/[name].[ext]"
}
],
{ copyUnmodified: true }
) /*,
new ExtractTextPlugin({ filename: `./widgets/${packageConfig.packagePath}/${name}/ui/${widgetName}.css` }),*/
]
};
const previewConfig = {
entry: `./src/${widgetName}.webmodeler.tsx`,
output: {
path: path.resolve(__dirname, "dist/tmp"),
filename: `widgets/${widgetName}.webmodeler.js`,
libraryTarget: "commonjs"
},
resolve: {
extensions: [".ts", ".js", ".tsx"]
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
compilerOptions: {
module: "CommonJS"
}
}
},
{ test: /\.css$/, use: "raw-loader" }
]
},
mode: "production",
// devtool: "inline-source-map",
externals: ["react", "react-dom"],
plugins: [new MomentLocalesPlugin()]
};
module.exports = [widgetConfig, previewConfig];