-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack-config-factory.ts
61 lines (54 loc) · 1.5 KB
/
webpack-config-factory.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
const path = require('path');
export type WebpackConfigFactoryOptions = {
entrySrc: string
buildPath: string
libName: string
libraryTarget: string
debug?: boolean,
externals?: string[]
plugins?: unknown[]
}
export function createWebpackConfig (options: WebpackConfigFactoryOptions, excludePaths: string[] = []) {
const libName = options.libName;
const buildPath = path.resolve(options.buildPath);
console.log('Generating config for library:', libName, 'with options:\n', options, '\n');
console.log('Resolved build path:', buildPath);
const baseConfig = {
mode: options.debug ? 'development' : 'production',
entry: options.entrySrc,
externals: options.externals,
output: {
path: buildPath,
publicPath: '/' + options.buildPath + '/',
filename: libName + '.' + options.libraryTarget + '.js',
library: libName,
libraryTarget: options.libraryTarget,
sourceMapFilename: '[file].map',
globalObject: 'this'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.html', '.css'],
fallback: {
http: false,
fs: false
}
},
module: {
rules: [
{
test: /\.ts?$/,
loader: 'ts-loader'
}
]
},
devtool: options.debug ? 'inline-source-map' : 'source-map',
optimization: {
minimize: !options.debug
},
plugins: options.plugins || [],
watchOptions: {
poll: 1000 // Check for changes every second
}
};
return baseConfig;
}