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
87 lines (81 loc) · 2.73 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
const web = require('@neutrinojs/web');
const babelMerge = require('babel-merge');
const merge = require('deepmerge');
module.exports =
(opts = {}) =>
(neutrino) => {
const options = merge(
{
hot: true,
babel: {},
},
opts,
);
let reactHotLoader = false;
try {
// Attempt to load react-hot-loader from the user's installation.
reactHotLoader = require.resolve('react-hot-loader/babel');
} catch (err) {} // eslint-disable-line no-empty
Object.assign(options, {
babel: babelMerge(
{
plugins: [
// The RHL plugin is enabled in production too since it removes the `hot(module)(...)`
// wrapper, allowing webpack to use its concatenate modules optimization.
options.hot && reactHotLoader,
process.env.NODE_ENV === 'production' && [
require.resolve('babel-plugin-transform-react-remove-prop-types'),
{
removeImport: true,
},
],
].filter(Boolean),
presets: [
[
require.resolve('@babel/preset-react'),
{
// Enable development helpers both in development and testing.
development: process.env.NODE_ENV !== 'production',
// When spreading props, use inline object with spread elements directly instead of
// Babel's extend helper or Object.assign. @babel/env will still transpile these down
// if required for the target browsers.
useSpread: true,
},
],
],
},
options.babel,
),
});
neutrino.use(web(options));
const lintRule = neutrino.config.module.rules.get('lint');
if (lintRule) {
lintRule.use('eslint').tap(
// Don't adjust the lint configuration for projects using their own .eslintrc.
(lintOptions) =>
lintOptions.useEslintrc
? lintOptions
: merge(lintOptions, {
baseConfig: {
plugins: ['react', 'react-hooks'],
rules: {
// Enforces the rules of hooks:
// https://reactjs.org/docs/hooks-rules.html
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
settings: {
react: {
version: 'detect',
},
},
},
}),
);
}
neutrino.config.resolve.alias
.set('react-native', 'react-native-web')
.end()
.extensions.prepend('.web.js')
.prepend('.web.jsx');
};