UNPKG

1 kBJavaScriptView Raw
1import { existsSync } from 'fs';
2import { join } from 'path';
3import chalk from 'chalk';
4import webpack from 'webpack';
5
6export function warnIfExists(cwd) {
7 const filePath = join(cwd, 'webpack.config.js');
8 if (existsSync(filePath)) {
9 console.log(
10 chalk.yellow(
11 `⚠️ ⚠️ ⚠️ It\\'s not recommended to use ${chalk.bold(
12 'webpack.config.js',
13 )}, since it\\'s major or minor version upgrades may result in incompatibility. If you insist on doing so, please be careful of the compatibility after upgrading.`,
14 ),
15 );
16 console.log();
17 }
18}
19
20export function applyWebpackConfig(cwd, config) {
21 const filePath = join(cwd, 'webpack.config.js');
22 if (existsSync(filePath)) {
23 let customConfigFn = require(filePath); // eslint-disable-line
24 if (customConfigFn.default) {
25 customConfigFn = customConfigFn.default;
26 }
27 return customConfigFn(config, {
28 // eslint-disable-line
29 webpack,
30 });
31 } else {
32 return config;
33 }
34}