forked from riedeljan/insomnia-universal-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
75 lines (62 loc) · 1.81 KB
/
webpack.common.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
"use strict";
const path = require("path");
const webpack = require("webpack");
const WebpackNodeExternals = require("webpack-node-externals");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
// Common webpack configuration / utilities
const projectConstants = require("./webpack.constants.js");
// Global constants
const MODE_PRODUCTION = "production";
const MODE_DEVELOPMENT = "development";
module.exports = {
// Global constants
PRODUCTION: MODE_PRODUCTION,
DEVELOPMENT: MODE_DEVELOPMENT,
// Common webpack configuration
getCommonConfiguration: (type) => {
const outputSuffix = "";
return {
target: "node",
entry: {
index: "./src/index.tsx"
},
output: {
path: path.join(__dirname, `${projectConstants.outputRoot}`),
filename: `[name].${outputSuffix && (outputSuffix !== "") ? outputSuffix + "." : ""}js`,
library: {
type: "commonjs"
}
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
modules: [
"node_modules"
]
},
module: {
rules: [
{test: /\.tsx$/i, loader: "ts-loader"},
{test: /\.ts$/i, loader: "ts-loader"},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
externals: [WebpackNodeExternals({
allowlist: []
})],
plugins: [
new CleanWebpackPlugin({
dry: false,
verbose: true,
cleanOnceBeforeBuildPatterns: projectConstants.outputPaths.map((value, index, array) => path.join(process.cwd(), `${value}`))
}),
new webpack.DefinePlugin({
DEVELOPMENT: JSON.stringify(type === MODE_DEVELOPMENT),
"process.env.NODE_ENV": JSON.stringify(type)
})
]
};
}
};