philhawksworth / netlify-plugin-minify-html

26 stars 8 forks source link

minifyJS does not seem to work #1

Open steverandy opened 4 years ago

steverandy commented 4 years ago

The config that I use:

[[plugins]]
  package = "netlify-plugin-minify-html"
  [plugins.inputs]
    contexts = ["production", "branch-deploy", "deploy-preview"]
  [plugins.inputs.minifierOptions]
    minifyJS = true
    minifyCSS = true
    removeComments = true
    collapseWhitespace = true

It looks like the plugin does not work and netlify serves the original html. Not sure what I'm missing. Can you help? Thanks.

philhawksworth commented 4 years ago

This bug should be fixed in v0.2.3 Try updating to use that version in your package.json.

steverandy commented 4 years ago

I just tried and getting the following error message:

Screenshot 2020-06-08 at 7 19 38 PM
philhawksworth commented 4 years ago

hmmm. Thanks @steverandy. Would it be possible to share any info about the site you are using this on? Is it in a public repo anywhere?

steverandy commented 4 years ago

The repo is private.

This is the netlify.toml config that I use:

[build]
  publish = "public"
  command = "npm run build"

[build.environment]
  NODE_VERSION = "12.16.3"
  NODE_OPTIONS = "--max_old_space_size=4096"
  GATSBY_TELEMETRY_DISABLED = "1"

[[plugins]]
  package = "netlify-plugin-gatsby-cache"

[[plugins]]
  package = "netlify-plugin-minify-html"
  [plugins.inputs]
    contexts = ["production", "branch-deploy", "deploy-preview"]
  [plugins.inputs.minifierOptions]
    minifyJS = true
    minifyCSS = true
    removeComments = true
    collapseWhitespace = true
philhawksworth commented 4 years ago

Not seeing anything untoward in your toml. Tricky to debug without more insight into the site itself since I can't replicate this issue. Are you able to perform a build locally via the netlify cli which would also run the build locally for you?

# install the Netlify CLI
npm i --g netlify-cli

# run a Netlify build from your project directory
netlify build

It would be interesting to know if this works locally.

steverandy commented 4 years ago

Got the same error on local build.

However, it works if I set the sync option

comp({
  compressor: htmlMinifier,
  input: constants.PUBLISH_DIR + '/**/*.html',
  output: '$1.html',
  replaceInPlace: true,
  options: inputs.minifierOptions,
  sync: true
});
chrispecoraro commented 2 years ago

If you're using Gatsby, there is a directory that gets produced that throws an error due to no file check in the version of the underlying package. I submitted a fix that I submitted to repository a year ago, but it hasn't been merged yet: https://github.com/srod/node-minify/pull/1117