Repository navigation
Expand file tree
/
Copy pathwebpack-build-test.js
More file actions
111 lines (106 loc) · 3.42 KB
/
Copy pathwebpack-build-test.js
File metadata and controls
111 lines (106 loc) · 3.42 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
// this config must be JS so that the karma plugin can load it
const path = require('path');
const webpack = require('webpack');
const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
const appRoot = path.resolve(projectRoot, appConfig.root);
return {
devtool: 'inline-source-map',
context: path.resolve(__dirname, './'),
resolve: {
extensions: ['', '.ts', '.js'],
root: appRoot
},
entry: {
test: path.resolve(appRoot, appConfig.test)
},
output: {
path: './dist.test',
filename: '[name].bundle.js'
},
module: {
preLoaders: [
{
test: /\.ts$/,
loader: 'tslint-loader',
exclude: [
path.resolve(projectRoot, 'node_modules')
]
},
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
path.resolve(projectRoot, 'node_modules/rxjs'),
path.resolve(projectRoot, 'node_modules/@angular')
]
}
],
loaders: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
query: {
tsconfig: path.resolve(appRoot, appConfig.tsconfig),
module: 'commonjs',
target: 'es5',
useForkChecker: true
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [/\.e2e\.ts$/]
},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' },
{ test: /\.html$/, loader: 'html-loader', exclude: [path.resolve(appRoot, appConfig.index)] }
],
postLoaders: [
{
test: /\.(js|ts)$/, loader: 'sourcemap-istanbul-instrumenter-loader',
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/
],
query: { 'force-sourcemap': true }
}
]
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
}),
new webpack.NormalModuleReplacementPlugin(
// This plugin is responsible for swapping the environment files.
// Since it takes a RegExp as first parameter, we need to escape the path.
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
path.resolve(appRoot, appConfig.environments[environment])
)
],
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: `./${appConfig.root}`
},
node: {
fs: 'empty',
global: 'window',
process: false,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
}
module.exports.getWebpackTestConfig = getWebpackTestConfig;