forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.neutrinorc.js
174 lines (163 loc) · 4.92 KB
/
.neutrinorc.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const merge = require('deepmerge');
const copy = require('@neutrinojs/copy');
const reactLint = require('@mozilla-frontend-infra/react-lint');
const react = require('@neutrinojs/react');
const karma = require('@neutrinojs/karma');
const { join, resolve } = require('path');
const fs = require('fs');
const generateEnvJs = require('./generate-env-js');
const DEFAULT_PORT = 5080;
const STATIC_DIR = join(__dirname, 'src/static');
const port = process.env.PORT || DEFAULT_PORT;
require('@babel/register')({
presets: [require.resolve('@babel/preset-env')],
cache: false,
});
const theme = require('./src/theme').default;
module.exports = {
options: {
mains: {
index: 'index.jsx',
docs: 'docs.jsx',
},
},
use: [
reactLint({
parserOptions: {
ecmaFeatures: {
legacyDecorators: true
},
},
plugins: ['react-hooks'],
rules: {
'react/no-access-state-in-setstate': 'off',
'babel/no-unused-expressions': 'off',
'linebreak-style': 'off',
'react-hooks/rules-of-hooks': 'error',
'react/jsx-props-no-spreading': 'off',
// We use @babel/plugin-proposal-class-properties to allow those
'react/static-property-placement': 'off',
// We use @babel/plugin-proposal-class-properties to allow those
'react/state-in-constructor': 'off',
},
}),
react({
html: {
template: './src/index.html',
},
devServer: {
port,
historyApiFallback: {
disableDotRule: true,
rewrites: [
{ from: /^\/docs/, to: '/docs.html' },
],
},
proxy: {
'/login': {
target: 'http://localhost:3050',
},
'/graphql': {
target: 'http://localhost:3050',
},
'/subscription': {
ws: true,
changeOrigin: true,
target: 'ws://localhost:3050',
},
},
},
}),
(neutrino) => {
neutrino.config.node.set('Buffer', true);
// The shell view requires this
neutrino.config
.externals(merge(neutrino.config.get('externals'), {
bindings: 'bindings'
}));
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => ({
...options,
plugins: options.plugins
// @babel/plugin-proposal-decorators needs to come before @babel/plugin-proposal-class-properties
.filter(plugin => !plugin[0].includes('plugin-proposal-class-properties'))
.concat([
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: false }],
[require.resolve('@babel/plugin-proposal-optional-chaining'), { loose: true }],
[require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), { loose: true }],
]).filter(Boolean)
}));
neutrino.config.module
.rule('graphql')
.test(/\.graphql$/)
.include
.add(neutrino.options.source)
.end()
.use('gql-loader')
.loader(require.resolve('graphql-tag/loader'));
// The JSONStream module's main file has a Node.js shebang
// which Webpack doesn't like loading as JS
neutrino.config.module
.rule('shebang')
.test(/JSONStream/)
.use('shebang')
.loader('shebang-loader');
neutrino.config.module
.rule('markdown')
.test(/\.mdx?$/)
.use('babel-loader')
.loader('babel-loader')
.options({
presets: [require.resolve('@babel/preset-react')],
})
.end()
.use('mdx-loader')
.loader('mdx-loader');
neutrino.config.module
.rule('all-contributors')
.test(/\.all-contributorsrc$/)
.use('json-loader')
.loader('json-loader');
},
(neutrino) => {
neutrino.config.resolve
.alias.set('taskcluster-ui', resolve(__dirname, 'src/'));
},
(neutrino) => {
// Generate env.js, combining env vars into the build, when
// GENERATE_ENV_JS is set
const envJs = join(STATIC_DIR, 'env.js');
if (process.env.GENERATE_ENV_JS) {
generateEnvJs(envJs);
} else {
// just so that we never end up accidentally including something
// in a production build
if (fs.existsSync(envJs)) {
fs.unlinkSync(envJs);
}
}
neutrino.use(copy({
patterns: [
{
context: 'src/static',
from: '**/*',
to: 'static',
},
],
}));
},
karma({
plugins: [
'karma-firefox-launcher',
],
client: {
mocha: {
ui: 'tdd',
},
},
}),
],
};