-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (52 loc) · 1.8 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
const { ConfigurationError } = require('neutrino/errors')
const STYLE_EXTENSIONS = /\.(css|scss|sass|less|styl|pcss)$/
const STYLE_MODULES_EXTENSIONS = /\.module\.(css|scss|sass|less|styl|pcss)$/
const JSX_EXTENSIONS = /\.(jsx|tsx)$/
function reactScopedComponent (settings = {}) {
return function (neutrino) {
neutrino.config.module
.rule('scoped-component')
.test(JSX_EXTENSIONS)
.post() // Should process pure JS after all transformations
.include
.merge([neutrino.options.source, neutrino.options.tests])
.end()
.use('react-scoped-styles')
.loader(require.resolve('./loaders/component-loader'))
.options(settings)
}
}
function reactScopedStyle (settings = {}) {
return function (neutrino) {
let styleRule = neutrino.config.module.rules.get('style')
if (!styleRule) {
throw new ConfigurationError(`’react-scoped-styles’ middleware requires ’neutrino.config.module.rule("style")’ to be defined before`)
}
neutrino.config.module
.rule('scoped-style')
.after('style') // Should process pure CSS before it is passed to css-loader but after CSS preprocessors
.test(STYLE_EXTENSIONS)
.include
.merge([neutrino.options.source, neutrino.options.tests])
.end()
.exclude
.add(STYLE_MODULES_EXTENSIONS)
.end()
.set('issuer', JSX_EXTENSIONS)
.use('react-scoped-styles')
.loader(require.resolve('./loaders/style-loader'))
.options(settings)
.end()
}
}
module.exports = function () {
let scopedStylesSettings = {
globalsPrefix: 'app'
}
return function (neutrino) {
neutrino.use(reactScopedComponent(scopedStylesSettings))
neutrino.use(reactScopedStyle(scopedStylesSettings))
}
}
module.exports.reactScopedComponent = reactScopedComponent
module.exports.reactScopedStyle = reactScopedStyle