-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (58 loc) · 1.6 KB
/
index.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
/**
* Elm webpack block.
*
* @see https://github.com/elm-community/elm-webpack-loader
*/
module.exports = elm
/**
* @param {object} [options]
* @param {number} [options.maxInstances] Maximum instances of elm that can spawned.
* @param {string} [options.cwd] Custom location for your elm files.
* @return {Function}
*/
function elm (options = {}, isProduction) {
isProduction = typeof isProduction === 'boolean'
? isProduction
: process.env.NODE_ENV === 'production'
const productionDefaultConfig = {
hot: false,
options: {}
}
const developmentDefaultConfig = {
hot: true,
options: {
verbose: true,
warn: true,
debug: true
}
}
const main = context => prevConfig => {
context.elm = Object.assign({}, context.elm, isProduction ? productionDefaultConfig : developmentDefaultConfig)
context.elm.options = Object.assign(context.elm.options, options)
// Return unchanged config (configuration will be created by the post hook)
return prevConfig
}
return Object.assign(main, { post: postConfig })
}
function postConfig (context, util) {
const elmLoader = {
loader: 'elm-webpack-loader',
options: context.elm.options
}
const elmHotLoader = {
loader: 'elm-hot-loader'
}
const loaderConfig = Object.assign({
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: context.elm.hot ? [elmHotLoader, elmLoader] : [elmLoader]
}, context.match)
return util.merge({
resolve: {
extensions: [ '.elm' ]
},
module: {
rules: [ loaderConfig ]
}
})
}