-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·98 lines (86 loc) · 2.01 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
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
// @flow
/**
* Webpack block for PureScript using the purs-loader
*
* @see https://github.com/ethul/purs-loader
*/
export type Config = Object
export type Helpers = {merge: Config => Config}
export type Block = {
(context: Object, helpers: Helpers): Config => Config,
post: (context: Object, helpers: Helpers) => Config => Config
}
export type Options = {
psc?: string,
pscArgs?: Object,
pscBundle?: string,
pscBundleArgs?: Object,
pscIde?: Boolean,
pscIdeClient?: string,
pscIdeClientArgs?: Object,
pscIdeServer?: string,
pscIdeServerArgs?: Object,
pscIdeColors?: Boolean,
pscPackage?: Boolean,
bundleOutput?: string,
bundleNamespace?: string,
bundle?: Boolean,
warnings?: Boolean,
watch?: Boolean,
output?: string,
src?: Array<string>
}
const productionDefaultConfig = {
options: {
psc: 'psa',
warnings: false,
},
}
const developmentDefaultConfig = {
options: {
psc: 'psa',
warnings: true,
watch: true,
},
}
export default function purescript (
options: Options = {},
isProduction: ?boolean
) {
isProduction = typeof isProduction === 'boolean'
? isProduction
: process.env.NODE_ENV === 'production'
const main = context => prevConfig => {
context.purescript = Object.assign(
{},
context.purescript,
isProduction ? productionDefaultConfig : developmentDefaultConfig
)
context.purescript.options = Object.assign(
context.purescript.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 {options} = context.purescript
const loaderConfig = Object.assign(
{
test: /\.purs$/,
exclude: options.exclude || /node_modules/,
use: [{loader: 'purs-loader', options}],
},
context.match
)
return util.merge({
resolve: {
extensions: ['.purs'],
},
module: {
rules: [loaderConfig],
},
})
}