-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.ts
61 lines (58 loc) · 2.03 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
import path from 'path';
import webpack from 'webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import NodemonPlugin from 'nodemon-webpack-plugin';
import ModuleDependencyWarning from 'webpack/lib/ModuleDependencyWarning';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const shouldAnalyzeBundle = process.env.WEBPACK_ANALYZE;
class IgnoreNotFoundExportPlugin {
apply(compiler) {
const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/;
function doneHook(stats) {
stats.compilation.warnings = stats.compilation.warnings.filter(function(warn) {
if (warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message)) {
return false;
}
return true;
});
}
if (compiler.hooks) {
compiler.hooks.done.tap('IgnoreNotFoundExportPlugin', doneHook);
} else {
compiler.plugin('done', doneHook);
}
}
}
const webpackconfiguration: webpack.Configuration = {
mode: 'development',
entry: path.resolve(__dirname, 'src', 'morphism.ts'),
devtool: isProd ? 'hidden-source-map' : 'source-map',
output: {
filename: 'morphism.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
globalObject: 'this',
sourceMapFilename: 'morphism.map',
library: 'Morphism',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
module: {
rules: [{ test: /\.(ts|js)x?$/, use: ['babel-loader', 'source-map-loader'], exclude: /node_modules/ }],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
async: false,
checkSyntacticErrors: true,
reportFiles: ['**', '!**/*.json', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
silent: true,
}),
new NodemonPlugin(),
new IgnoreNotFoundExportPlugin(),
shouldAnalyzeBundle ? new BundleAnalyzerPlugin({ generateStatsFile: true }) : null,
].filter(plugin => plugin),
};
export default webpackconfiguration;