-
Notifications
You must be signed in to change notification settings - Fork 43
/
webpack.config.js
100 lines (95 loc) · 2.84 KB
/
webpack.config.js
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
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const CopyPlugin = require('copy-webpack-plugin');
var isCoverage = process.env.NODE_ENV === 'coverage';
const mode = process.argv.includes('--prod')
? 'production'
: 'development';
module.exports = {
entry: mode === 'production' ? {
'index': './src/index.ts',
} : {
'tests': isCoverage
? ['./tests-index.js']
: ['webpack/hot/poll?100', './tests-index.js']
},
watch: mode === 'development',
optimization: {
minimize: false,
},
target: 'node',
devtool: 'source-map',
mode,
externals: [
nodeExternals({
whitelist: ['webpack/hot/poll?100'],
}),
],
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
transpileOnly: mode === 'development',
},
},
...isCoverage ? [
{
test: /\.ts$/,
exclude: /\.spec\.ts$/,
enforce: 'post',
use: {
loader: 'istanbul-instrumenter-loader',
options: { esModules: true }
}
}] : [],
// {
// test: /\.pegjs$/,
// loader: 'pegjs-loader'
// },
{
test: /\.ne$/,
use: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.ne$/],
transpileOnly: mode === 'development',
}
},
{
loader: path.resolve(__dirname, 'nearley-loader.js')
}
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.ne'],
},
plugins: mode === 'production' ? [
new CopyPlugin({
patterns: [
{ from: 'package.json', to: 'package.json' },
{ from: 'readme.md', to: 'readme.md' },
],
}),
]
: [
// required
new webpack.HotModuleReplacementPlugin(),
],
output: {
library: '',
libraryTarget: 'commonjs',
path: mode === 'production'
? path.join(__dirname, 'lib')
: path.join(__dirname, 'output'),
// this ensures that source maps are mapped to actual files (not "webpack:" uris)
devtoolModuleFilenameTemplate: mode === 'production'
? info => info.resourcePath
: info => path.resolve(__dirname, info.resourcePath),
},
};