Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does nothing. #306

Open
arthurwolf opened this issue Aug 22, 2022 · 2 comments
Open

Does nothing. #306

arthurwolf opened this issue Aug 22, 2022 · 2 comments

Comments

@arthurwolf
Copy link

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
Copy link
Author

arthurwolf commented Aug 22, 2022

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.

@oshliaer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants