Update CopyPlugin options

This commit is contained in:
Pavel Djundik 2020-05-16 21:32:33 +03:00
parent c3d8855ec3
commit bc7bf9870c
2 changed files with 60 additions and 35 deletions

View file

@ -19,6 +19,10 @@ describe("public folder", function () {
expect(fs.existsSync(path.join(publicFolder, "thelounge.webmanifest"))).to.be.true;
});
it("audio files are copied", function () {
expect(fs.existsSync(path.join(publicFolder, "audio", "pop.wav"))).to.be.true;
});
it("index HTML file is not copied", function () {
expect(fs.existsSync(path.join(publicFolder, "index.html"))).to.be.false;
expect(fs.existsSync(path.join(publicFolder, "index.html.tpl"))).to.be.false;
@ -32,6 +36,8 @@ describe("public folder", function () {
it("style files are built", function () {
expect(fs.existsSync(path.join(publicFolder, "css", "style.css"))).to.be.true;
expect(fs.existsSync(path.join(publicFolder, "css", "style.css.map"))).to.be.true;
expect(fs.existsSync(path.join(publicFolder, "themes", "default.css"))).to.be.true;
expect(fs.existsSync(path.join(publicFolder, "themes", "morning.css"))).to.be.true;
});
it("style files contain expected content", function (done) {
@ -55,4 +61,15 @@ describe("public folder", function () {
expect(fs.existsSync(path.join(publicFolder, "js", "loading-error-handlers.js"))).to.be
.true;
});
it("service worker has cacheName set", function (done) {
fs.readFile(path.join(publicFolder, "service-worker.js"), "utf8", function (err, contents) {
expect(err).to.be.null;
expect(contents.includes("const cacheName =")).to.be.true;
expect(contents.includes("__HASH__")).to.be.false;
done();
});
});
});

View file

@ -91,42 +91,50 @@ const config = {
new MiniCssExtractPlugin({
filename: "css/style.css",
}),
new CopyPlugin([
{
from: "./node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff*",
to: "fonts/[name].[ext]",
},
{
from: "./client/js/loading-error-handlers.js",
to: "js/[name].[ext]",
},
{
from: "./client/*",
to: "[name].[ext]",
ignore: ["index.html.tpl", "service-worker.js"],
},
{
from: "./client/service-worker.js",
to: "[name].[ext]",
transform(content) {
return content
.toString()
.replace("__HASH__", isProduction ? Helper.getVersionCacheBust() : "dev");
new CopyPlugin({
patterns: [
{
from:
"./node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff*",
to: "fonts/[name].[ext]",
},
},
{
from: "./client/audio/*",
to: "audio/[name].[ext]",
},
{
from: "./client/img/*",
to: "img/[name].[ext]",
},
{
from: "./client/themes/*",
to: "themes/[name].[ext]",
},
]),
{
from: "./client/js/loading-error-handlers.js",
to: "js/[name].[ext]",
},
{
from: "./client/*",
to: "[name].[ext]",
globOptions: {
ignore: ["**/index.html.tpl", "**/service-worker.js"],
},
},
{
from: "./client/service-worker.js",
to: "[name].[ext]",
transform(content) {
return content
.toString()
.replace(
"__HASH__",
isProduction ? Helper.getVersionCacheBust() : "dev"
);
},
},
{
from: "./client/audio/*",
to: "audio/[name].[ext]",
},
{
from: "./client/img/*",
to: "img/[name].[ext]",
},
{
from: "./client/themes/*",
to: "themes/[name].[ext]",
},
],
}),
// socket.io uses debug, we don't need it
new webpack.NormalModuleReplacementPlugin(
/debug/,