-
Notifications
You must be signed in to change notification settings - Fork 101
/
index.js
98 lines (91 loc) · 2.29 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
exports.babel = function (config, opts) {
config.plugins = (config.plugins || []).concat([
require.resolve('@babel/plugin-transform-react-constant-elements'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
[require.resolve('@babel/plugin-proposal-decorators'), {
legacy: true
}],
require.resolve('@babel/plugin-proposal-class-properties'),
[require.resolve('@babel/plugin-transform-react-jsx'), {
pragma: 'h',
pragmaFrag: 'Fragment'
}]
]);
if (opts.production) {
config.plugins.push(
require.resolve('babel-plugin-transform-react-remove-prop-types')
);
}
}
exports.terser = {
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
sourceMap: true,
output: {
comments: false
},
mangle: true,
compress: {
properties: true,
keep_fargs: false,
pure_getters: true,
collapse_vars: true,
warnings: false,
sequences: true,
dead_code: true,
drop_debugger: true,
comparisons: true,
conditionals: true,
evaluate: true,
booleans: true,
loops: true,
unused: true,
hoist_funs: true,
if_return: true,
join_vars: true,
drop_console: false,
pure_funcs: [
'classCallCheck',
'_classCallCheck',
'_possibleConstructorReturn',
'Object.freeze',
'invariant',
'warning'
]
}
}
}
exports.webpack = function (config, opts) {
// Preact 8.x vs Preact X
let compat = 'preact-compat';
let preact = 'preact';
let isPreactX = 0;
try {
require.resolve('preact/compat');
compat = 'preact/compat';
isPreactX = 1;
} catch (err) {
if (opts.production) {
preact = 'preact/dist/preact.min.js';
}
}
// Apply aliases
Object.assign(config.resolve.alias, {
'react': compat,
'react-dom': compat,
'preact': preact,
'preact-compat': compat,
'react-addons-css-transition-group': 'preact-css-transition-group',
'create-react-class': 'preact-compat/lib/create-react-class'
});
let { ProvidePlugin } = opts.webpack;
let definitions = { h: ['preact', 'h'] };
if (isPreactX) definitions.Fragment = ['preact', 'Fragment'];
config.plugins.push(new ProvidePlugin(definitions));
// Attach `async!` loader
config.resolveLoader = config.resolveLoader || {};
config.resolveLoader.alias = config.resolveLoader.alias || {};
config.resolveLoader.alias.async = require.resolve('@preact/async-loader');
}