This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
110 lines (102 loc) · 3.55 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
import webpack, { WebpackPluginInstance } from "webpack";
import "webpack-dev-server";
import path from "path";
import CircularDependencyPlugin from "circular-dependency-plugin";
import chalk from "chalk";
import _ from "lodash";
enum Environment {
LOCAL = "local",
TEST = "test",
DEV = "development",
STAGING = "staging",
PRODUCTION = "production",
}
interface ConfigEnv {
ENVIRONMENT?: Environment;
}
const config = (env: ConfigEnv = {}): webpack.Configuration => {
env.ENVIRONMENT =
env.ENVIRONMENT ??
(process.env.NODE_ENV as Environment) ??
Environment.LOCAL;
const webpackEnv: { [key: string]: string } = {};
console.info(chalk.bold.cyan("- NUCLUI -"));
_.forEach(env, (v, k) => {
if (v) {
console.info(`${chalk.blue(k)}: ${chalk.bold.blue(v)}`);
webpackEnv[`process.env.${k}`] = JSON.stringify(v);
}
});
console.info("");
const isProduction = env.ENVIRONMENT === Environment.PRODUCTION;
const isStaging = env.ENVIRONMENT === Environment.STAGING;
const CircularDependency = new CircularDependencyPlugin({
exclude: /a\.js|node_modules/,
failOnError: true,
cwd: process.cwd(),
});
return {
entry: ["babel-polyfill", "docs/index.tsx"],
output: {
path: path.resolve(__dirname, "docs/public/dist"),
filename: "bundle.js",
},
module: {
rules: [
{
use: ["babel-loader", "eslint-loader"],
test: /\.js$/,
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
enforce: "pre",
use: [
{
loader: "ts-loader",
options: {
configFile: "docs/tsconfig.json",
logLevel:
isProduction || isStaging ? "warn" : "info",
},
},
"eslint-loader",
],
exclude: /node_modules/,
},
],
},
resolve: {
modules: [path.resolve(__dirname), "node_modules"],
extensions: [".tsx", ".ts", ".js", ".json"],
alias: {
"nuclui": path.resolve(__dirname, "src/"),
"@utils": path.resolve(__dirname, "src/utils/"),
"@components": path.resolve(__dirname, "src/components/"),
"@config": path.resolve(__dirname, "src/config/"),
"@theme": path.resolve(__dirname, "src/theme/"),
"@fonts": path.resolve(__dirname, "src/fonts/"),
"@hooks": path.resolve(__dirname, "src/hooks/"),
"@styles": path.resolve(__dirname, "src/styles/"),
},
},
plugins: [
CircularDependency as unknown as WebpackPluginInstance,
new webpack.DefinePlugin(webpackEnv),
],
mode: isProduction || isStaging ? "production" : "development",
devtool: isProduction || isStaging ? "source-map" : "eval-source-map",
devServer: {
port: 3000,
host: "0.0.0.0",
historyApiFallback: true,
devMiddleware: {
publicPath: "/dist/",
},
static: {
directory: path.join(__dirname, "docs/public"),
},
},
};
};
export default config;