Skip to content

Commit c7c4c19

Browse files
committed
chore: rename
1 parent 2d69e3b commit c7c4c19

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed
Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
const { getProjectPath, resolve } = require('./utils/projectHelper'); // eslint-disable-line import/order
1+
import { getProjectPath, resolve } from './utils/projectHelper';
2+
import * as path from 'path';
3+
import * as webpack from 'webpack';
4+
import WebpackBar from 'webpackbar';
5+
import { merge } from 'webpack-merge';
6+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
7+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
8+
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
9+
import TerserPlugin from 'terser-webpack-plugin';
10+
import CleanUpStatsPlugin from './utils/CleanUpStatsPlugin';
11+
import { Configuration } from 'webpack';
12+
import { readJsonSync } from 'fs-extra';
13+
import getBabelCommonConfig from './getBabelCommonConfig';
214

3-
// Show warning for webpack
4-
process.traceDeprecation = true;
5-
6-
// Normal requirement
7-
const path = require('path');
8-
const webpack = require('webpack');
9-
const WebpackBar = require('webpackbar');
10-
const webpackMerge = require('webpack-merge');
11-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
12-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
13-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
14-
const TerserPlugin = require('terser-webpack-plugin');
15-
const CleanUpStatsPlugin = require('./utils/CleanUpStatsPlugin');
15+
interface PackageJson {
16+
name: string;
17+
version: string;
18+
}
1619

1720
const svgRegex = /\.svg(\?v=\d+\.\d+\.\d+)?$/;
1821
const svgOptions = {
@@ -24,11 +27,18 @@ const imageOptions = {
2427
limit: 10000,
2528
};
2629

27-
function getWebpackConfig(modules) {
28-
const pkg = require(getProjectPath('package.json'));
29-
const babelConfig = require('./getBabelCommonConfig')(modules || false);
30+
interface GetWebpackConfigFunction {
31+
(modules?: boolean): Configuration[];
32+
webpack: typeof webpack;
33+
svgRegex: RegExp;
34+
svgOptions: typeof svgOptions;
35+
imageOptions: typeof imageOptions;
36+
}
37+
38+
const getWebpackConfig: GetWebpackConfigFunction = (modules?: boolean): Configuration[] => {
39+
const pkg: PackageJson = readJsonSync(getProjectPath('package.json'));
40+
const babelConfig = getBabelCommonConfig(modules || false);
3041

31-
// babel import for components
3242
babelConfig.plugins.push([
3343
resolve('babel-plugin-import'),
3444
{
@@ -38,7 +48,6 @@ function getWebpackConfig(modules) {
3848
},
3949
]);
4050

41-
// Other package
4251
if (pkg.name !== 'antd') {
4352
babelConfig.plugins.push([
4453
resolve('babel-plugin-import'),
@@ -55,7 +64,7 @@ function getWebpackConfig(modules) {
5564
babelConfig.plugins.push(require.resolve('./replaceLib'));
5665
}
5766

58-
const config = {
67+
const config: Configuration = {
5968
devtool: 'source-map',
6069

6170
output: {
@@ -144,8 +153,6 @@ function getWebpackConfig(modules) {
144153
},
145154
],
146155
},
147-
148-
// Images
149156
{
150157
test: svgRegex,
151158
loader: resolve('url-loader'),
@@ -188,7 +195,6 @@ All rights reserved.
188195
if (process.env.RUN_ENV === 'PRODUCTION') {
189196
const entry = ['./index'];
190197

191-
// Common config
192198
config.externals = {
193199
react: {
194200
root: 'React',
@@ -218,8 +224,7 @@ All rights reserved.
218224
],
219225
};
220226

221-
// Development
222-
const uncompressedConfig = webpackMerge({}, config, {
227+
const uncompressedConfig = merge({}, config, {
223228
entry: {
224229
[pkg.name]: entry,
225230
},
@@ -232,8 +237,7 @@ All rights reserved.
232237
],
233238
});
234239

235-
// Production
236-
const prodConfig = webpackMerge({}, config, {
240+
const prodConfig = merge({}, config, {
237241
entry: {
238242
[`${pkg.name}.min`]: entry,
239243
},
@@ -256,11 +260,11 @@ All rights reserved.
256260
}
257261

258262
return [config];
259-
}
263+
};
260264

261265
getWebpackConfig.webpack = webpack;
262266
getWebpackConfig.svgRegex = svgRegex;
263267
getWebpackConfig.svgOptions = svgOptions;
264268
getWebpackConfig.imageOptions = imageOptions;
265269

266-
module.exports = getWebpackConfig;
270+
export default getWebpackConfig;

0 commit comments

Comments
 (0)