-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.test.js
More file actions
155 lines (141 loc) · 4.44 KB
/
Copy pathwebpack.test.js
File metadata and controls
155 lines (141 loc) · 4.44 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
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
154
155
const helpers = require('./helpers');
const path = require('path');
const webpack = require('webpack');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
const isCoverageEnabled = helpers.isTestCoverageEnabled();
module.exports = function (options) {
return {
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
alias: helpers.createTsConfigPathAliases(require('./tsconfig.json'))
},
module: {
rules: (() => {
let rules = [
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader',
exclude: [
helpers.root('node_modules')
]
},
{
test: /\.ts$/,
loaders: [
{ loader: 'ts-loader', options: { transpileOnly: true } },
'angular2-template-loader'
],
exclude: [/\.e2e\.ts$/]
},
{
test: /\.json$/,
use: 'json-loader',
exclude: [helpers.root('src/index.html')]
},
{
test: /\.css$/,
use: ['to-string-loader', 'css-loader'],
exclude: [helpers.root('src/index.html')]
},
{
test: /\.scss$/,
use: [
'to-string-loader',
'css-loader',
'sass-loader'
// Uncomment the following loader to add resources that should be included in all component SASS styles
// {
// loader: 'sass-resources-loader',
// options: {
// resources: [
// helpers.root('src/styles/base/variables/*.scss'),
// helpers.root('src/styles/base/mixins/*.scss')
// ]
// }
// }
],
exclude: [helpers.root('src/index.html')]
},
{
test: /\.html$/,
use: 'raw-loader',
exclude: [helpers.root('src/index.html')]
},
/**
* Instruments JS files with Istanbul for subsequent code coverage reporting.
* Instrument only testing sources.
*
* See: https://github.com/deepsweet/istanbul-instrumenter-loader
*/
];
if (isCoverageEnabled) {
rules.push({
enforce: 'post',
test: /\.(js|ts)$/,
use: {
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
},
include: helpers.root('src'),
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/
]
});
}
return rules;
})()
},
plugins: [
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
watch: ['./src']
}),
new DefinePlugin({
'ENV': JSON.stringify(ENV),
'process.env': {
'ENV': JSON.stringify(ENV),
'NODE_ENV': JSON.stringify(ENV)
}
}),
// Provides context to Angular's use of System.import. See: https://github.com/angular/angular/issues/11580
new ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
helpers.root('src'), // location of your src
{
// your Angular Async Route paths relative to this root directory
}
),
new LoaderOptionsPlugin({
debug: false,
options: {
// legacy options go here
context: helpers.root('.')
}
}),
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
})
],
performance: {
hints: false
},
node: {
global: true,
process: true,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
}