forked from ParkYoungWoong/webpack-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
33 lines (27 loc) · 1.05 KB
/
webpack.config.ts
File metadata and controls
33 lines (27 loc) · 1.05 KB
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
import { createBasicConfig, checkNodejsVersion } from './confs';
import type { Configuration } from 'webpack';
import type { SelfDefineOptions } from './confs';
/**
* @description Export a Config Function.
* See: https://webpack.js.org/configuration/configuration-types/#exporting-a-function
* @param environments environments, like dev, prod ...
* @returns a webpack config
*/
const webpackConfigCallback = (environments: Record<string, unknown>): Configuration => {
checkNodejsVersion();
// use env and process.env
const { dev, prod } = environments;
const { NODE_ENV = 'development' } = process.env;
const isDev = !!dev && NODE_ENV === 'development';
const isProd = !!prod && NODE_ENV === 'production';
// options for basicConfig
const basicConfigOptions: SelfDefineOptions = {
title: 'react-ts-webpack-starter',
lang: 'zh-CN',
isDev,
isProd,
isCompiledWithSourceMap: () => isProd,
};
return createBasicConfig(basicConfigOptions).toConfig();
};
export default webpackConfigCallback;