forked from stevejhiggs/gulp-webpack-typescript-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
112 lines (98 loc) · 2.74 KB
/
webpack.config.js
File metadata and controls
112 lines (98 loc) · 2.74 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const findTslintFile = (options) => {
if (options.tslintFile) {
if (fs.existsSync(options.tslintFile)) {
console.log(`using custom tslint file at ${options.tslintFile}`);
return options.tslintFile;
}
console.warn(`custom tslint file not found at ${options.tslintFile}`);
}
const rootTslint = path.resolve('./tslint.json');
if (fs.existsSync(rootTslint)) {
console.log(`using custom tslint file at ${rootTslint}`);
return rootTslint;
}
// default internal file
return path.join(__dirname, 'tslint.json');
};
const findTsconfigFile = (options) => {
if (options.tsConfigFile) {
if (fs.existsSync(options.tsConfigFile)) {
console.log(`using tsconfig file at ${options.tsConfigFile}`);
return options.tsConfigFile;
}
console.warn(`tsconfig file not found at ${options.tsConfigFile}`);
}
// check for config at the same level as root
const rootEntryPoint = path.resolve('./tsconfig.json');
if (fs.existsSync(rootEntryPoint)) {
console.log(`using tsconfig file at ${rootEntryPoint}`);
return rootEntryPoint;
}
};
module.exports = (options) => {
const lintingOptions = {
formatter: 'stylish',
configFile: findTslintFile(options)
};
const tsConfigFile = findTsconfigFile(options);
if (tsConfigFile) {
lintingOptions.tsConfigFile = tsConfigFile;
}
const config = {
cache: true,
mode: 'development',
resolve: {
modules: [
'node_modules',
path.join(__dirname, 'node_modules')
],
extensions: ['.js', '.ts', '.jsx', '.tsx']
},
entry: options.entryPoints,
externals:[],
output: {
path: path.join(options.outputDir),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
enforce: 'pre',
loader: require.resolve('tslint-loader'),
query: lintingOptions
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: require.resolve('ts-loader')
}
]
},
plugins: [],
devtool: 'cheap-source-map',
performance: {
maxAssetSize: 1500000,
maxEntrypointSize: 1500000
}
};
if (options.isNodeLibrary) {
config.output.libraryTarget = 'commonjs2';
config.target = 'node';
config.plugins.push(new webpack.DefinePlugin({
'process.env': 'process.env'
}));
}
if (options.isNodeLibrary) {
config.externals.push(nodeExternals());
}
if (options.externals) {
config.externals = config.externals.concat(options.externals);
}
return config;
};