This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathindex.js
71 lines (65 loc) · 2.08 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
const web = require('@neutrinojs/web');
const compileLoader = require('@neutrinojs/compile-loader');
const loaderMerge = require('@neutrinojs/loader-merge');
const { join } = require('path');
const merge = require('deepmerge');
const MODULES = join(__dirname, 'node_modules');
module.exports = (neutrino, opts = {}) => {
const options = merge({
hot: true,
hotEntries: [require.resolve('react-hot-loader/patch')],
babel: {}
}, opts);
Object.assign(options, {
babel: compileLoader.merge({
plugins: [
[
require.resolve('babel-plugin-transform-react-jsx'),
{ pragma: 'createElement' }
],
[
require.resolve('babel-plugin-jsx-pragmatic'),
{
module: 'react',
export: 'createElement',
import: 'createElement'
}
],
...(
process.env.NODE_ENV === 'development'
? [
...(options.hot ? [require.resolve('react-hot-loader/babel')] : []),
[require.resolve('babel-plugin-transform-class-properties'), { spec: true }],
require.resolve('babel-plugin-transform-es2015-classes')
]
: [
[require.resolve('babel-plugin-transform-class-properties'), { spec: true }]
]
)
],
presets: [require.resolve('babel-preset-react')]
}, options.babel)
});
neutrino.use(web, options);
neutrino.config.when(neutrino.config.module.rules.has('lint'), () => {
neutrino.use(loaderMerge('lint', 'eslint'), {
plugins: ['react'],
rules: {
// Shutting this off allows ESLint to not fail when using JSX without an explicit
// "react" import when coupled with the "jsx-pragmatic" and "transform-react-jsx"
// babel plugins above
'react/react-in-jsx-scope': 'off'
}
});
});
neutrino.config
.resolve
.batch((resolve) => {
resolve.modules.add(MODULES);
resolve.alias.set('react-native', 'react-native-web');
})
.end()
.resolveLoader
.modules
.add(MODULES);
};