-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
94 lines (84 loc) · 2.32 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
import Encore from "@symfony/webpack-encore";
import fs from "fs";
import path from "path";
import uikit from "uikit/package.json" with { type: "json" };
const paths = {
public: "/build",
source: path.resolve(import.meta.dirname, "assets"),
output: path.resolve(import.meta.dirname, "public/build"),
};
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}/styles/email.scss`)
.addStyleEntry("css/editmode", `${paths.source}/styles/editmode.css`)
// JavaScript
.enableSingleRuntimeChunk()
.splitEntryChunks()
.configureBabel(() => {}, {
useBuiltIns: "usage",
corejs: 3,
})
.configureDefinePlugin((options) => {
options.LOG = false;
options.VERSION = JSON.stringify(uikit.version);
})
.addAliases({
"uikit-util": "uikit/src/js/util/index.js",
})
// CSS
.enableSassLoader(
(options) => {
options.sassOptions.quietDeps = true;
options.sassOptions.silenceDeprecations = ["import"];
},
{ resolveUrlLoader: false },
)
.enablePostCssLoader()
// Copy images
.copyFiles({
from: `${paths.source}/images`,
to: "[path][name].[hash:8].[ext]",
pattern: /\.(jpe?g|png|gif|svg|webp)$/i,
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" };
})
.configureWatchOptions((options) => {
options.poll = true;
})
.configureImageRule(
{
filename: "images/[name].[hash:8][ext]",
},
(rule) => {
rule.exclude = [`${paths.source}/custom/icons`];
},
)
.addRule({
loader: "raw-loader",
test: /\.svg$/,
include: [`${paths.source}/custom/icons`],
})
.addPlugin({
apply: (compiler) => {
compiler.hooks.afterEmit.tap("AfterEmitPlugin", () => {
fs.writeFileSync(
`${paths.output}/environment.json`,
`{"environment": "${Encore.isProduction() ? "prod" : "dev"}"}`,
);
});
},
});
export default Encore.getWebpackConfig();