-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
65 lines (63 loc) · 1.99 KB
/
webpack.config.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
62
63
64
65
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import path from 'path';
import { Configuration, DefinePlugin } from 'webpack';
import nodeExternals from 'webpack-node-externals';
import { WebpackCustomRunScriptsPlugin } from '@sellerspot/webpack-run-scripts-custom-plugin';
const webpackConfiguration = (env: {
production?: boolean;
development?: boolean;
}): Configuration => {
const isProduction = env.production ? true : false;
return {
entry: './src',
target: 'node',
externals: [nodeExternals()],
resolve: {
extensions: ['.ts', '.d.ts'],
},
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.js',
libraryTarget: 'umd',
umdNamedDefine: true,
library: 'universal-functions',
globalObject: 'this', // refernceError: self is not defined fix
},
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
options: {
transpileOnly: !isProduction, // this generates .d.ts when it is false
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
eslint: {
files: './src',
},
}),
!isProduction
? new WebpackCustomRunScriptsPlugin({
command: 'npm run build:dev',
})
: new DefinePlugin({}),
],
devtool: false,
watch: !isProduction,
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: false,
__dirname: false,
},
};
};
export default webpackConfiguration;