-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.ts
153 lines (148 loc) · 4.67 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as webpack from 'webpack';
import * as fs from 'fs';
import * as Path from 'path';
const sourcePath = Path.join(__dirname, 'src');
const buildPath = Path.join(__dirname, 'dist');
const context = __dirname;
const defaultOptions = {
test: false,
coverage: false,
};
export default (options: any = defaultOptions) => {
const stats: webpack.Options.Stats = {
version: false,
maxModules: 0,
children: false,
warningsFilter: [
/Critical dependency/,
/export .* was not found in/,
/System.import/,
/Cannot find SourceMap/,
],
};
const config: any = {
mode: 'development',
context: context,
entry: (() => {
if (options.test) return false;
return {
app: './example/main.ts',
};
})(),
output: {
path: buildPath,
publicPath: '',
filename: '[name].js',
},
devtool: (() => {
if (options.test) return 'inline-source-map';
return 'cheap-source-map';
})(),
devServer: {
overlay: true,
noInfo: false,
contentBase: [buildPath],
historyApiFallback: true,
inline: true,
stats,
},
node: {
// workaround for webpack-dev-server issue
// https://github.com/webpack/webpack-dev-server/issues/60#issuecomment-103411179
fs: 'empty',
net: 'empty',
// Buffer: false,
},
target: 'web',
resolve: {
extensions: ['.ts', '.js'],
},
module: {
exprContextCritical: false,
rules: [
{
parser: { amd: false }
},
{
test: /\.ts$/,
use: (() => {
let result: any[] = [
{
loader: 'awesome-typescript-loader',
options: {
useTranspileModule: true,
isolatedModules: true,
transpileOnly: true,
}
},
'angular-router-loader',
];
return result;
})(),
},
{
test: /\.component\.html$/,
use: [
{ loader: 'raw-loader' }
]
},
{
test: /index\.ejs$/,
use: [
{ loader: 'ejs-loader' },
]
},
{
test: /\.component\.css$/,
use: [
{ loader: 'css-to-string-loader' },
{ loader: 'css-loader', options: { importLoaders: 1 } },
]
},
{
test: /\.css$/,
use: (() => {
let result = [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
];
return result;
})(),
},
{
test: /\.(woff|woff2|eot|ttf|png|svg)$/,
use: [
{ loader: 'file-loader', options: { name: 'i/[name]-[hash:6].[ext]' } }
]
},
...(options.coverage ? [
{
enforce: 'post',
test: /\.ts$/,
exclude: [
/\.spec\.ts$/,
/node_modules/,
/example/,
/src[\\/]app[\\/]testing/,
],
use: {
loader: 'istanbul-instrumenter-loader',
options: { esModules: true },
},
}
] : [])
],
},
plugins: (() => {
const result: any[] = [];
const HtmlWebpackPlugin = require('html-webpack-plugin');
result.push(new HtmlWebpackPlugin({
template: './example/index.ejs',
minify: false,
excludeChunks: [],
}));
return result;
})()
};
return config;
}