Skip to content

Commit

Permalink
Merge pull request #74 from mm-paulie/feature/73-add-quality-option-f…
Browse files Browse the repository at this point in the history
…or-optimizing-images

Feature/73 add quality option for optimizing images
  • Loading branch information
mm-paulie authored Aug 15, 2023
2 parents cb4420c + d0e073d commit 4024a7c
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/webpack/config/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const sanitizeFilename = require("sanitize-filename");

const WriteFilePlugin = require("../plugin/WriteFilePlugin");
const ZipFilesPlugin = require("../plugin/ZipFilesPlugin");
const OptimizeBundleToFilesizePlugin = require('../plugin/OptimizeBundleToFilesizePlugin');
const OptimizeBundleToFilesizePlugin = require("../plugin/OptimizeBundleToFilesizePlugin");
const CopyFilesPlugin = require("../plugin/CopyFilesPlugin");
const HtmlWebpackInlineSVGPlugin = require("../plugin/HtmlWebpackInlineSVGPlugin");

Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = function createConfig({
richmediarcFilepath,
outputPath,

options: {mode = DevEnum.DEVELOPMENT, stats = false} = {
options: { mode = DevEnum.DEVELOPMENT, stats = false } = {
mode: DevEnum.DEVELOPMENT,
stats: false,
},
Expand Down Expand Up @@ -132,7 +132,7 @@ module.exports = function createConfig({
loaderArray.push({
loader: "esbuild-loader",
options: {
target: 'es2015'
target: "es2015",
},
});
}
Expand Down Expand Up @@ -271,29 +271,28 @@ module.exports = function createConfig({
// don't optimize images if optimizeToFileSize is set to true
imageLoadersArray.push({
loader: path.resolve(path.join(__dirname, "../loader/ImageOptimizeLoader.js")),
options: {}
options: {},
});
}

return imageLoadersArray;
},
},


{
test: /\.(ttf|woff|woff2)$/,
use: [
richmediarc.settings.fontsBase64
? {
loader: "url-loader",
}
loader: "url-loader",
}
: {
loader: "file-loader",
options: {
// name: `[name]${namedHashing}.[ext]`,
name: `${namedHashing}.[ext]`,
loader: "file-loader",
options: {
// name: `[name]${namedHashing}.[ext]`,
name: `${namedHashing}.[ext]`,
},
},
},
{
loader: path.resolve(path.join(__dirname, "../loader/RichmediaFontLoader.js")),
options: {
Expand Down Expand Up @@ -359,30 +358,32 @@ module.exports = function createConfig({
if (fs.existsSync(staticPath)) {
config.plugins.push(
new CopyFilesPlugin({
fromPath: staticPath
fromPath: staticPath,
})
);
}

if (richmediarc.settings.type === "flashtalking") {
console.log('found flashtalking ad')
console.log("found flashtalking ad");

const outputString = `FT.manifest({
"filename": "index.html",
"width": ${richmediarc.settings.size.width},
"height": ${richmediarc.settings.size.height},
"clickTagCount": 1
});`
});`;

config.plugins.push(new WriteFilePlugin({
filePath: './',
fileName: 'manifest.js',
content: outputString
}))
config.plugins.push(
new WriteFilePlugin({
filePath: "./",
fileName: "manifest.js",
content: outputString,
})
);
}

if (richmediarc.settings.type === "adform") {
let clickTags = richmediarc.settings.clickTags || {clickTAG: "http://www.adform.com"};
let clickTags = richmediarc.settings.clickTags || { clickTAG: "http://www.adform.com" };
let obj = {
version: "1.0",
title: richmediarc.settings.bundleName || bundleName,
Expand All @@ -399,11 +400,13 @@ module.exports = function createConfig({
source: "index.html",
};

config.plugins.push(new WriteFilePlugin({
filePath: './',
fileName: 'manifest.json',
content: JSON.stringify(obj, null, 2)
}))
config.plugins.push(
new WriteFilePlugin({
filePath: "./",
fileName: "manifest.json",
content: JSON.stringify(obj, null, 2),
})
);
}

config.optimization = {
Expand All @@ -428,19 +431,18 @@ module.exports = function createConfig({
}

if (mode === DevEnum.PRODUCTION) {

config.plugins.push(
richmediarc.settings.optimizeToFileSize ?
new OptimizeBundleToFilesizePlugin({
outputPath: path.join(outputPath, "../"),
filename: `${bundleName}.zip`,
maxFileSize: richmediarc.settings.maxFileSize * 1024,
lowestQuality: 60,
}) :
new ZipFilesPlugin({
outputPath: path.join(outputPath, "../"),
filename: `${bundleName}.zip`
})
richmediarc.settings.optimizeToFileSize
? new OptimizeBundleToFilesizePlugin({
outputPath: path.join(outputPath, "../"),
filename: `${bundleName}.zip`,
maxFileSize: richmediarc.settings.maxFileSize * 1024,
lowestQuality: richmediarc.settings.lowestImageQuality ? richmediarc.settings.lowestImageQuality : 60,
})
: new ZipFilesPlugin({
outputPath: path.join(outputPath, "../"),
filename: `${bundleName}.zip`,
})
);
}

Expand Down

0 comments on commit 4024a7c

Please sign in to comment.