1 4
import * as path from 'path';
2 4
import { DefinePlugin } from 'webpack';
3
import Config from 'webpack-chain';
4 4
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
5 4
import alias from '../utils/alias';
6 4
import getEnvironment from '../utils/env';
7 4
import * as webpack from 'webpack';
8
import Builder from '../Builder';
9

10 4
export default function baseConfig(config: Config, builder: Builder) {
11 4
  config.resolveLoader.modules
12
    .merge(['node_modules', path.join(__dirname, './loaders')])
13
    .end()
14
    .extensions.merge(['.js', '.ts']);
15

16 4
  config.mode((process.env.NODE_ENV as any) === 'production' ? 'production' : 'development');
17

18 4
  config.context(builder.options.cwd);
19

20 4
  config.resolve.alias.merge(alias(builder.options, builder.target));
21

22 4
  config.output.path(path.join(builder.options.cwd, builder.options.output));
23

24 4
  const env = getEnvironment(builder.options, builder.target);
25 4
  config.plugin('webpack-define-plugin').use(DefinePlugin, [env.stringified]);
26 4
  config.plugin('provide-regeneratorRuntime').use(webpack.ProvidePlugin, [
27
    {
28
      regeneratorRuntime: 'regenerator-runtime',
29
    },
30
  ]);
31

32 4
  if (process.env.NODE_ENV === 'production') {
33 0
    config.plugin('clean-webpack-plugin').use(CleanWebpackPlugin);
34
  }
35

36 4
  config.devServer
37
    .publicPath(config.get('publicPath'))
38
    .compress(true)
39
    .hot(true)
40
    .open(false)
41
    .historyApiFallback(true)
42
    .noInfo(true);
43

44 4
  return config;
45
}

Read our documentation on viewing source code .

Loading