-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
122 lines (119 loc) · 3.98 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const htmlLoader = require('neutrino-middleware-html-loader');
const styleLoader = require('neutrino-middleware-style-loader');
const fontLoader = require('neutrino-middleware-font-loader');
const imageLoader = require('neutrino-middleware-image-loader');
const tsLoader = require('neutrino-middleware-ts-loader');
const env = require('neutrino-middleware-env');
const htmlTemplate = require('neutrino-middleware-html-template');
const chunk = require('neutrino-middleware-chunk');
const hot = require('neutrino-middleware-hot');
const copy = require('neutrino-middleware-copy');
const clean = require('neutrino-middleware-clean');
const minify = require('neutrino-middleware-minify');
const loaderMerge = require('neutrino-middleware-loader-merge');
const namedModules = require('neutrino-middleware-named-modules');
const { join, dirname } = require('path');
const { path, pathOr } = require('ramda');
const MODULES = join(__dirname, 'node_modules');
function devServer({ config }, options) {
config.devServer
.host(options.host)
.port(parseInt(options.port, 10))
.https(options.https)
.contentBase(options.contentBase)
.historyApiFallback(true)
.hot(true)
.publicPath('/')
.stats({
assets: false,
children: false,
chunks: false,
colors: true,
errors: true,
errorDetails: true,
hash: false,
modules: false,
publicPath: false,
timings: false,
version: false,
warnings: true
});
}
module.exports = (neutrino) => {
const defaultEntry = join(neutrino.options.source, 'index.js');
const defaultTsEntry = join(neutrino.options.source, 'index.ts');
neutrino.use(env);
neutrino.use(htmlLoader);
neutrino.use(styleLoader);
neutrino.use(fontLoader);
neutrino.use(imageLoader);
neutrino.use(htmlTemplate, neutrino.options.html);
neutrino.use(namedModules);
neutrino.use(tsLoader);
neutrino.config
.when(process.env.NODE_ENV !== 'test', () => neutrino.use(chunk))
.target('web')
.context(neutrino.options.root)
.entry('index')
.add(neutrino.options.entry === defaultEntry ? defaultTsEntry : neutrino.options.entry)
.end()
.output
.path(neutrino.options.output)
.publicPath('./')
.filename('[name].bundle.js')
.chunkFilename('[id].[chunkhash].js')
.end()
.resolve
.modules
.add('node_modules')
.add(neutrino.options.node_modules)
.add(MODULES)
.end()
.extensions
.add('.js')
.add('.json')
.end()
.end()
.resolveLoader
.modules
.add(neutrino.options.node_modules)
.add(MODULES)
.end()
.end()
.node
.set('console', false)
.set('global', true)
.set('process', true)
.set('Buffer', true)
.set('__filename', 'mock')
.set('__dirname', 'mock')
.set('setImmediate', true)
.set('fs', 'empty')
.set('tls', 'empty')
.end()
.when(process.env.NODE_ENV === 'development', config => {
const protocol = process.env.HTTPS ? 'https' : 'http';
const host = process.env.HOST || pathOr('localhost', ['options', 'config', 'devServer', 'host'], neutrino);
const port = process.env.PORT || pathOr(5000, ['options', 'config', 'devServer', 'port'], neutrino);
neutrino.use(hot);
neutrino.use(devServer, {
host,
port,
https: pathOr(protocol === 'https', ['options', 'config', 'devServer', 'https'], neutrino),
contentBase: neutrino.options.source
});
config
.devtool('inline-source-map')
.entry('index')
.add(`webpack-dev-server/client?${protocol}://${host}:${port}/`)
.end();
}, config => {
neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(minify);
neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*', '*.ts*'] }
});
config.output.filename('[name].[chunkhash].bundle.js');
});
};