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

Introduce a config option for collapsing newlines #85

Closed
wants to merge 1 commit into from

Conversation

mataha
Copy link
Contributor

@mataha mataha commented Dec 17, 2023

This commit introduces a config option that, when enabled, collapses leading and trailing newlines inserted while combining assets within a single file.

This is necessary because, by the time this plugin runs (i.e. during the generateBundle stage), it is too late to perform any code minification.

This commit introduces a config option that, when enabled, collapses leading
and trailing newlines inserted while combining assets within a single file.

This is necessary because, by the time this plugin runs (i.e. during the
`generateBundle` stage), it is too late to perform any code minification.
@richardtallent
Copy link
Owner

Sorry, I'm not following why this is needed?

@richardtallent
Copy link
Owner

No information provided, closing.

@mataha
Copy link
Contributor Author

mataha commented Feb 3, 2024

Apologies - I didn't see your previous message.

Consider the following example:

package.json
{
  "name": "example",
  "type": "module",
  "version": "1.0.0",
  "scripts": {
    "build": "vite build",
    "serve": "vite serve"
  },
  "devDependencies": {
    "vite": "^5.0.12",
    "vite-plugin-singlefile": "^1.0.0"
  }
}
vite.config.mjs
import { defineConfig } from "vite";
import { viteSingleFile } from "vite-plugin-singlefile";

export default defineConfig({
    plugins: [
        viteSingleFile({
            useRecommendedBuildConfig: true,
            removeViteModuleLoader: true,
        }),
    ],
    build: {
        minify: true,
    }
});
index.html
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" crossorigin type="text/css" href="./index.css" />
  </head>
  <body>
    Hello World!
  </body>
</html>
index.css
html {
    box-sizing: border-box;
    text-size-adjust: none;
}

The result:

<!doctype html>
<html>
  <head>
    <style>
html{box-sizing:border-box;text-size-adjust:none}

</style>
  </head>
  <body>
    Hello World!
  </body>
</html>

Notice the newlines. I would expect the following instead:

<!doctype html>
<html>
  <head>
    <style>html{box-sizing:border-box;text-size-adjust:none}</style>
  </head>
  <body>
    Hello World!
  </body>
</html>

If you're wondering why is this important for me - when on 512 Kbps, every shaven byte matters.

@richardtallent
Copy link
Owner

This has been resolved in v2.0

@mataha mataha deleted the feat/collapse-newlines branch February 12, 2024 18:53
@mataha
Copy link
Contributor Author

mataha commented Feb 12, 2024

That almost did it - see #91.

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

Successfully merging this pull request may close these issues.

2 participants