/
webpack.config.js
101 lines (91 loc) · 2.63 KB
/
webpack.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
94
95
96
97
98
99
100
101
const Encore = require('@symfony/webpack-encore');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const fs = require('fs');
const { resolve } = require('path');
const { version } = require('uikit/package.json');
const paths = {
output: resolve(__dirname, './public/build/'),
pattern: /\.(jpe?g|png|gif|svg|webp)$/i,
public: 'build',
source: resolve(__dirname, './assets'),
vendor: resolve(__dirname, './node_modules'),
};
Encore
// Set output and public paths
.setOutputPath(`${paths.output}/`)
.setPublicPath(`/${paths.public}`)
// Clean output before build
.cleanupOutputBeforeBuild()
// Entries
.addEntry('js/app', `${paths.source}/js/app.js`)
.addStyleEntry('css/email', `${paths.source}/scss/email.scss`)
.addStyleEntry('css/editmode', `${paths.source}/scss/editmode.scss`)
// JavaScript
.enableSingleRuntimeChunk()
.enableEslintPlugin()
.splitEntryChunks()
.configureBabel(() => {}, {
includeNodeModules: [
'uikit',
],
useBuiltIns: 'usage',
corejs: 3,
})
.configureDefinePlugin((options) => {
options.LOG = false;
options.VERSION = JSON.stringify(version);
})
.addAliases({ 'uikit-util': `${paths.vendor}/uikit/src/js/util` })
// CSS
.enableSassLoader((options) => {
options.sassOptions.quietDeps = true;
}, { resolveUrlLoader: false })
.enablePostCssLoader()
.addPlugin(new StyleLintPlugin())
// Copy and optimize images
.copyFiles({
from: `${paths.source}/images`,
to: '[path][name].[hash:8].[ext]',
pattern: paths.pattern,
context: paths.source,
})
// Source maps and cache buster
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
// Advanced config options
.configureDevServerOptions((options) => {
options.allowedHosts = 'all';
options.server = {
type: 'https',
options: {
cert: '/etc/ssl/dev.local+4.pem',
key: '/etc/ssl/dev.local+4-key.pem',
},
};
})
.configureWatchOptions((options) => {
options.poll = true;
options.ignored = `${paths.vendor}/`;
})
.configureImageRule({}, (rule) => {
rule.exclude = [
`${paths.vendor}/uikit`,
`${paths.source}/custom/icons`,
];
})
.addRule({
loader: 'raw-loader',
test: /\.svg$/,
include: [
`${paths.vendor}/uikit`,
`${paths.source}/custom/icons`,
],
})
.addPlugin({
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
fs.writeFileSync(`${paths.output}/environment.json`, `{"environment": "${Encore.isProduction() ? 'prod' : 'dev'}"}`);
});
},
});
module.exports = Encore.getWebpackConfig();