-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreact.config.js
64 lines (58 loc) · 1.93 KB
/
preact.config.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
import { resolve } from "path";
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
export default {
/**
* Function that mutates the original webpack config.
* Supports asynchronous changes when a promise is returned (or it's an async function).
*
* @param {object} config - original webpack config.
* @param {object} env - options passed to the CLI.
* @param {WebpackConfigHelpers} helpers - object with useful helpers for working with the webpack config.
* @param {object} options - this is mainly relevant for plugins (will always be empty in the config), default to an empty object
**/
webpack(config, env, helpers, options) {
delete config.entry.polyfills;
config.output.filename = "mobalytics-widgets.js";
config.output.chunkFilename = "[name].[hash:5].js";
config.plugins = config.plugins.filter(plugin => !(plugin instanceof MiniCssExtractPlugin));
config.module.rules = config.module.rules.map(rule => {
if (rule.loader === 'babel-loader') {
const use = [
{
loader: 'babel-loader',
options: rule.options
},
{
loader: 'ts-loader'
}
];
return {
...rule,
loader: undefined,
options: undefined,
use
};
}
if (rule.use) {
return {
...rule,
use: rule.use.reduce((acc, loader) => {
loader !== MiniCssExtractPlugin.loader ? acc.push(loader) : acc.push(
'style-loader');
return acc;
}, []),
};
}
return rule;
});
// Use any `index` file, not just index.js
config.resolve.alias["preact-cli-entrypoint"] = resolve(
process.cwd(),
"src",
"index"
);
if (env.production) {
config.output.libraryTarget = 'umd';
}
}
};