-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
preact.config.js
60 lines (58 loc) · 2.09 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
const webpack = require('webpack');
const { GitRevisionPlugin } = require('git-revision-webpack-plugin');
import tailwindcss from 'tailwindcss';
import postcssCustomMedia from 'postcss-custom-media';
import optionalChaining from '@babel/plugin-proposal-optional-chaining';
import nullishOperator from '@babel/plugin-proposal-nullish-coalescing-operator';
/**
* Function that mutates original webpack config.
* Supports asynchronous changes when promise is returned.
*
* @param {object} config - original webpack config.
* @param {object} env - options passed to CLI.
* @param {WebpackConfigHelpers} helpers - object with useful helpers when working with config.
**/
export default function (config, env, helpers) {
const htmlWebpackPlugin = helpers.getPluginsByName(
config,
'HtmlWebpackPlugin',
)[0];
Object.assign(htmlWebpackPlugin.plugin.options.minify, {
removeComments: false,
collapseWhitespace: false,
});
htmlWebpackPlugin.plugin.options.preload = false;
htmlWebpackPlugin.plugin.options.favicon = false;
if (env.isProd) {
config.devtool = false; // disable sourcemaps
config.output.publicPath = './';
// config.plugins.push(
// new CommonsChunkPlugin({
// name: 'vendor',
// minChunks: ({ resource }) => /node_modules/.test(resource)
// })
// );
}
const babelLoader = helpers.getLoadersByName(config, 'babel-loader');
for (const result of babelLoader) {
console.log(result.loader.options);
result.loader.options.plugins.push(optionalChaining);
result.loader.options.plugins.push(nullishOperator);
}
const results = helpers.getLoadersByName(config, 'postcss-loader');
for (const result of results) {
result.loader.options.postcssOptions.plugins = [
postcssCustomMedia,
tailwindcss('./tailwind.config.js'),
...result.loader.options.postcssOptions.plugins,
];
}
const gitRevisionPlugin = new GitRevisionPlugin({
commithashCommand: 'rev-parse --short HEAD',
});
config.plugins.push(
new webpack.DefinePlugin({
__COMMITHASH__: JSON.stringify(gitRevisionPlugin.commithash()),
}),
);
}