-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.test.js
150 lines (146 loc) · 3.86 KB
/
webpack.test.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
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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const AllowMutateEsmExportsPlugin = require('./test/webpack/AllowMutateEsmExports');
const angularCommon = path.resolve(__dirname, 'src', 'angular-common.js');
const angularInjections = path.resolve(__dirname, 'src', 'require-angular-injections.js');
const chartJs = path.resolve(__dirname, 'src', 'frontend', 'components', 'Chart.js/Chart.js');
const materialAdmin = path.resolve(__dirname, 'src', 'frontend', 'js', 'material.js');
const momentPath = path.resolve(__dirname, 'node_modules', 'moment', 'moment.js');
const chaiPath = path.resolve(__dirname, 'node_modules', 'chai/chai.js');
const pugLoaderOptions = {
root: `${__dirname}/src/frontend/views`
};
const lodashPath = path.resolve(__dirname, 'node_modules', 'lodash', 'dist', 'lodash.js');
const BASE_HREF = process.env.BASE_HREF || '/';
module.exports = {
mode: 'development',
entry: './src/index.test.js',
devtool: 'source-map',
output: {
filename: 'bundle-test.js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
alias: {
'moment/moment.js': momentPath,
moment$: momentPath
}
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /codemirror/ }), // for summernote
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery',
'$window.$': 'jquery',
Chart: chartJs,
chai: chaiPath,
materialAdmin: materialAdmin,
angular: angularCommon,
_: lodashPath,
moment: momentPath,
'window.angularInjections': angularInjections
}),
/*
* To transform assets/index.pug to an HTML file, with webpack autoimporting the "main.js" bundle
*/
new HtmlWebpackPlugin({
template: './assets/index.pug',
filename: './index.html'
}),
new AllowMutateEsmExportsPlugin() // Allows mocking ES6 modules
],
module: {
rules: [
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader'
}
]
},
{
test: /all\.less$/,
use: [
{
loader: 'style-loader' // creates style nodes from JS strings
},
{
loader: 'css-loader' // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: {
javascriptEnabled: true
}
}
}
]
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'url-loader'
}
]
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
},
/*
* for the "index.html" file of this SPA.
*
*/
{
test: /assets\/index\.pug$/,
use: [
{
loader: 'html-loader'
},
{
loader: 'pug-html-loader',
options: {
data: {
base: BASE_HREF
}
}
}
]
},
{
test: /\.pug$/i,
exclude: /assets\/index\.pug$/,
use: [
{
loader: 'apply-loader'
},
{
loader: 'pug-loader',
options: pugLoaderOptions
}
]
},
{
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: '$'
}
},
{
test: /\.run.js$/,
loader: 'ignore-loader',
include: [
path.resolve(__dirname, 'src/frontend/js/modules/user-notification/user-notification.run.js'),
path.resolve(__dirname, 'src/frontend/js/modules/shortcuts/shortcuts.run.js')
]
}
]
}
};