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
79 lines (72 loc) · 2.5 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
const react = require('@neutrinojs/react');
const banner = require('@neutrinojs/banner');
const merge = require('deepmerge');
const nodeExternals = require('webpack-node-externals');
const { extname, join, basename } = require('path');
const { readdirSync } = require('fs');
module.exports =
(opts = {}) =>
(neutrino) => {
const options = merge(
{
html: process.env.NODE_ENV === 'development' && {
title: 'React Preview',
},
externals: opts.externals !== false && {},
style: {
extract: {
plugin: {
// Override the @neutrinojs/react production behaviour of hashed CSS
// filenames, and output to the build root, not an `assets/` subdirectory.
filename: '[name].css',
},
},
},
devtool: {
production: 'source-map',
},
targets: { browsers: 'ie 9' },
},
opts,
);
neutrino.config.when(
process.env.NODE_ENV === 'development',
() => {
neutrino.use(react(options));
},
() => {
const components = join(
neutrino.options.source,
options.components || 'components',
);
Object.keys(neutrino.options.mains).forEach((key) => {
delete neutrino.options.mains[key]; // eslint-disable-line no-param-reassign
});
readdirSync(components).forEach((component) => {
// eslint-disable-next-line no-param-reassign
neutrino.options.mains[basename(component, extname(component))] = {
entry: join(components, component),
};
});
const pkg = neutrino.options.packageJson || {};
const hasSourceMap =
(pkg.dependencies && 'source-map-support' in pkg.dependencies) ||
(pkg.devDependencies && 'source-map-support' in pkg.devDependencies);
neutrino.use(react(options));
neutrino.config
.when(options.externals, (config) =>
config.externals([nodeExternals(options.externals)]),
)
.when(hasSourceMap, () => neutrino.use(banner()))
// Disable the chunking behaviour inherited from the react preset
.optimization.splitChunks(false)
.runtimeChunk(false)
.end()
.output // Override hashed filename/subdirectory usage inherited from @neutrinojs/react.
.filename('[name].js')
.library('[name]')
.libraryTarget('umd')
.umdNamedDefine(true);
},
);
};