This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.ts
119 lines (115 loc) · 3.19 KB
/
webpack.config.ts
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
import fs = require("fs");
import path = require("path");
import webpack = require("webpack");
import HtmlWebpackPlugin = require("html-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const assetPath = path.resolve(__dirname, "./assets");
const outputPath = path.resolve(__dirname, "./public");
import "webpack-dev-server";
const sdkVersion = JSON.parse(
fs.readFileSync(
path.join(__dirname, "node_modules", "@rainway", "web", "package.json"),
{ encoding: "utf-8" },
),
).version;
console.log(`Detected Rainway SDK version ${sdkVersion}`);
const config: webpack.Configuration & { devServer: any } = {
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".css"],
plugins: [
// the SDK itself uses paths. pretty dumb that you need to point this plugin
// at the tsconfig of the dependency but there you go
//new TsconfigPathsPlugin({ configFile: "../rainway-sdk/tsconfig.json" }),
new TsconfigPathsPlugin({
configFile: "./tsconfig.json",
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".css"],
}),
],
fallback: { util: false },
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
projectReferences: true,
},
},
{
test: /\.js$/,
loader: "source-map-loader",
enforce: "post",
},
{
test: /\.css$/,
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: [require("autoprefixer")],
},
},
],
},
{
include: [assetPath],
test: /\.(png|svg|jpg|jpeg|otf|eot|woff2?|svg|ttf|js|json|webp|ico)$/,
use: {
loader: "file-loader",
options: {
name: "[path][name].[ext]",
},
},
},
],
},
entry: {
quick: "./src/quick-demo/index.tsx",
react: "./src/react-demo/index.tsx",
},
output: {
filename: "bundle.[name].[fullhash].js",
path: outputPath,
},
plugins: [
new HtmlWebpackPlugin({
chunks: ["quick"],
inject: "body",
template: path.resolve(assetPath, "./index-quick.ejs"),
inlineSource: ".(js|css)$",
filename: "quick/index.html",
}),
new HtmlWebpackPlugin({
chunks: ["react"],
inject: "body",
template: path.resolve(assetPath, "./index-react.ejs"),
inlineSource: ".(js|css)$",
filename: "index.html",
}),
new webpack.DefinePlugin({
__BUILD_DATE__: JSON.stringify(new Date().toISOString()),
__RAINWAY_SDK_VERSION__: JSON.stringify(sdkVersion),
__BUILD_COMMIT__: JSON.stringify(
require("child_process")
.execSync("git rev-parse --short HEAD")
.toString(),
),
}),
],
devtool: "inline-source-map",
mode: "development",
devServer: {
contentBase: outputPath,
host: "0.0.0.0",
port: 4445,
disableHostCheck: true,
inline: true,
stats: "minimal",
historyApiFallback: true,
},
};
module.exports = config;