-
Notifications
You must be signed in to change notification settings - Fork 49
/
preact.config.js
93 lines (80 loc) · 3.11 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
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
require('dotenv').config()
const path = require('path')
const glob = require('glob')
const assert = require('assert').strict
const PurgecssPlugin = require('purgecss-webpack-plugin')
export default (config, env, helpers) => {
if (env.production) {
// Disable sourcemaps
config.devtool = false
} else {
config.devServer.proxy = [{
path: '/api/**',
target: 'http://localhost:3000',
changeOrigin: true,
changeHost: true
}]
}
config.resolveLoader.modules.unshift(path.resolve(__dirname, 'client/lib/loaders'))
const { rule: { options: babelConfig } } = helpers.getLoadersByName(config, 'babel-loader')[0]
babelConfig.plugins.push('transform-export-extensions')
// The webpack base config has minicssextractplugin already loaded
config.plugins.push(
new PurgecssPlugin({
paths: glob.sync(env.source('**/*'), { nodir: true }),
// PurgeCSS does not correctly correctly recognize selectors of the form
// `[class*=" btn-"], [class^="btn-"]` that Cirrus uses extensively; it
// also does not recognize the comparison in the attribute selector and
// only picks up on `class`, so we have to whitelist all `class`
// selectors as we cannot target only the `btn-` selectors that are being
// improperly removed.
whitelistPatternsChildren: [/class.*/]
})
)
// Remove .svg from preconfigured webpack file-loader
;['file-loader', 'url-loader']
.flatMap(name => helpers.getLoadersByName(config, name))
.forEach(entry => {
entry.rule.test = /\.(woff2?|ttf|eot|jpe?g|png|webp|gif|mp4|mov|ogg|webm)(\?.*)?$/i
})
config.module.rules.push({
test: /\.svg$/,
loader: 'svg-sprite-loader',
options: {
runtimeGenerator: require.resolve('./client/lib/svg-icon-component-generator'),
runtimeOptions: {
iconModule: './components/icon'
}
}
})
const SizePluginWrapper = helpers.getPluginsByName(config, 'SizePlugin')[0]
if (SizePluginWrapper !== undefined) {
SizePluginWrapper.plugin.options = {
...SizePluginWrapper.plugin.options,
stripHash: (filename) => {
const regex = /\.[0-9a-f]+\.((esm\.)?js|css)/
const match = filename.match(regex)
if (match === null) {
return filename
}
return filename.slice(0, match.index) + '.' + match[1]
}
}
}
if (!env.production) {
const HtmlWebpackPluginsWrappers = helpers.getPluginsByName(config, 'HtmlWebpackPlugin')
for (const HtmlWebpackPluginWrapper of HtmlWebpackPluginsWrappers) {
const options = HtmlWebpackPluginWrapper.plugin.options
const loaderMatch = options.template.match(/^!!ejs-loader!(.*)$/)
assert(loaderMatch !== null)
options.template = `!!ejs-loader!mustache-config-loader!${loaderMatch[1]}`
}
}
const CopyPluginWrapper = helpers.getPluginsByName(config, 'CopyPlugin')[0]
if (CopyPluginWrapper !== undefined) {
const plugin = CopyPluginWrapper.plugin
plugin.patterns = plugin.patterns.filter(({ from }) => {
return !/node_modules[\\/]preact-cli[\\/]lib[\\/]resources[\\/](manifest.json|icon.png)$/.test(from)
})
}
}