@divriots/jampack 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
1
  const default_options = {
2
+ html: {
3
+ add_css_reset_as: 'inline',
4
+ },
2
5
  image: {
3
6
  embed_size: 1500,
4
7
  srcset_min_width: 640,
@@ -4,6 +4,9 @@ export type WebpOptions = {
4
4
  quality: number;
5
5
  };
6
6
  export type Options = {
7
+ html: {
8
+ add_css_reset_as: 'inline' | 'off';
9
+ };
7
10
  image: {
8
11
  embed_size: number;
9
12
  srcset_min_width: number;
package/dist/config.js CHANGED
@@ -5,14 +5,14 @@ import default_options from './config-default.js';
5
5
  import fast_options_override from './config-fast.js';
6
6
  const options = default_options;
7
7
  export function fast() {
8
- deepmerge(options, fast_options_override);
8
+ Object.assign(options, deepmerge(options, fast_options_override));
9
9
  }
10
10
  export async function loadConfig() {
11
11
  const proload = await load('jampack', { mustExist: false });
12
12
  if (proload) {
13
13
  console.log('Overriding default config with:');
14
14
  console.log(JSON.stringify(proload.value, null, 2));
15
- deepmerge(options, proload.value);
15
+ Object.assign(options, deepmerge(options, proload.value));
16
16
  }
17
17
  }
18
18
  export default options;
package/dist/index.js CHANGED
@@ -41,6 +41,11 @@ program
41
41
  .action(async (dir, options) => {
42
42
  $state.dir = dir;
43
43
  $state.args = options;
44
+ if (options) {
45
+ console.log('Options:');
46
+ console.log(options);
47
+ console.log('');
48
+ }
44
49
  // Override default config with config file
45
50
  await loadConfig();
46
51
  // Override config with fast options if set
package/dist/optimize.js CHANGED
@@ -79,13 +79,15 @@ async function analyse(file) {
79
79
  $('the-fold').remove();
80
80
  }
81
81
  // Add CSS to head
82
- const CSS = `<style>:where(img){height:auto;}</style>`;
83
- const heads = $('head');
84
- if (heads.length > 0) {
85
- heads.prepend(CSS);
86
- }
87
- else {
88
- (_a = $('html')) === null || _a === void 0 ? void 0 : _a.prepend(`<head>${CSS}</head>`);
82
+ if (config.html.add_css_reset_as === 'inline') {
83
+ const CSS = `<style>:where(img){height:auto;width:auto}</style>`;
84
+ const heads = $('head');
85
+ if (heads.length > 0) {
86
+ heads.prepend(CSS);
87
+ }
88
+ else {
89
+ (_a = $('html')) === null || _a === void 0 ? void 0 : _a.prepend(`<head>${CSS}</head>`);
90
+ }
89
91
  }
90
92
  if (!$state.args.nowrite) {
91
93
  await fs.writeFile(path.join($state.dir, file), $.html());
@@ -122,6 +124,13 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
122
124
  */
123
125
  const attrib_src = img.attr('src');
124
126
  if (!attrib_src) {
127
+ const attrib_data_src = img.attr('data-src');
128
+ if (attrib_data_src) {
129
+ // Contains attribute [data-src]
130
+ // Most likely, this is a Javascript lazy-loaded image
131
+ // Let's not mess with it and hope it's well done
132
+ return; // No warnings
133
+ }
125
134
  $state.reportIssue(htmlfile, {
126
135
  type: 'warn',
127
136
  msg: `Missing [src] on img - processing skipped.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {