inline-source icon indicating copy to clipboard operation
inline-source copied to clipboard

Does nothing.

Open arthurwolf opened this issue 1 year ago • 2 comments

My inline file is:

const { inlineSource } = require('inline-source');
const fs = require('fs');
const path = require('path');
const htmlpath = path.resolve('dist/pack.html');

inlineSource(htmlpath, {
  compress: true,
  rootpath: path.resolve('www'),
})
  .then((html) => {
    // Do something with html
    console.log(html);
  })
  .catch((err) => {
    // Handle error
  });

My html file is:


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="favicon.ico">
    <script src='/dist/workers/electrum-worker-dist.js'></script>
    <script src='/dist/workers/address-search-worker-dist.js'></script>
    <title>Test</title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

Running the script does absolutely nothing. The html it outputs is exactly the same as the source, nothing is inlined.

What am I doing wrong?

arthurwolf avatar Aug 22 '22 13:08 arthurwolf

I figured out I needed to add "inline" to the tags, but now that I have added that, I get zero output. no error, nothing.

arthurwolf avatar Aug 22 '22 13:08 arthurwolf

The next code should be fine

inline.js

const { inlineSource } = require('inline-source');
const path = require('path');
const htmlpath = path.resolve('./dist/pack.html');

(async () => {
  try {
    html = await inlineSource(htmlpath, {
      compress: false,
      attribute: false,
      ignore: ['ico'],
    });
    console.log(html);
  } catch (err) {
    console.error(err);
  }
})();

pack.html

Pathes were changed.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <link rel="icon" href="favicon.ico" />
    <script src="./workers/address-search-worker-dist.js"></script>
    <script src="./workers/electrum-worker-dist.js"></script>
    <title>Test</title>
  </head>
  <body>
    <noscript>
      <strong
        >We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please
        enable it to continue.</strong
      >
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

The files tree

├── dist
│   ├── pack.html
│   └── workers
│       ├── address-search-worker-dist.js
│       └── electrum-worker-dist.js
└── inline.js

oshliaer avatar Aug 24 '22 09:08 oshliaer