Skip to content

Conversation

jantimon
Copy link
Owner

This pull request contains #32 and #20.

It adds two new features:

@jantimon jantimon mentioned this pull request May 12, 2015
@SimenB
Copy link
Contributor

SimenB commented May 12, 2015

@jantimon Is it possible to use the this.minimize like html-loader does? So if I run webpack -p from the commandline, it's automatically minified?

https://github.com/webpack/html-loader/blob/master/index.js#L59

@sebastienbarre
Copy link
Contributor

@SimenB sorry, didn't get the time to look at it this weekend. Either way I can't replicate what html-loader is doing, i.e. var query = loaderUtils.parseQuery(this.query);, no such this.query is passed to html-webpack-plugin from webpack, that I can see. I assume said query is probably the query string that can be specified after a loader in module.loaders (as in image-loader?optimizationLevel=7&interlaced=false). I see css-loader also look at this.query, but that's about it amongst the loaders I have grepped. Though I assume I could always check if process.argv.indexOf('-p') > -1...

@SimenB
Copy link
Contributor

SimenB commented May 12, 2015

Ah ok. Too bad.

How about hooking into optimize phase? If I understand this correctly (probably not...) https://github.com/webpack/extract-text-webpack-plugin/blob/master/index.js#L188

@jantimon Looking in the same file. compilation.plugin("additional-assets", function(callback) {
Is that something we could use here? Really wish the plugin api was better documented 😆

@sebastienbarre
Copy link
Contributor

@SimenB I'm afraid not, from what I gather. The HTML itself seems to be generated in the 'emit' phase:
https://github.com/ampedandwired/html-webpack-plugin/blob/master/index.js#L13
Sticking a compilation.plugin("optimize", function() { inside doesn't appear to work, the code is not executed. optimize is probably a sub-stage that only makes sense during a compilation stage? Anyway, here is how I handle debug vs. prod in my webpack.config.js

var production = process.env.NODE_ENV === 'production' ||
  process.argv.indexOf('-p') > -1;
[...]
  var HtmlWebpackPlugin = require('html-webpack-plugin');
  var html_webpack_options = {
    template: 'src/assets/html/index.template.html'
  };
  if (production) {
    html_webpack_options.minify = {
      removeComments: true,
      collapseWhitespace: true,
      conservativeCollapse: true,
      minifyJS: true,
      minifyCSS: true
    };
  }
  config.plugins.push(new HtmlWebpackPlugin(html_webpack_options));

@jantimon
Copy link
Owner Author

@SimenB the query does something different - if you call a loader like myloader!myfile?x=1 then x=1 is your query.
If you call webpack with -p it just pushes the UglifyJsPlugin into the plugin array: https://github.com/webpack/webpack/blob/master/bin/convert-argv.js#L401

We could check iif the UglifyJsPlugin is part of compiler.options.plugins.

@SimenB
Copy link
Contributor

SimenB commented May 16, 2015

@jantimon Anything holding this up?

README.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing an a 😱

ampedandwired added a commit that referenced this pull request May 18, 2015
@ampedandwired ampedandwired merged commit c679de9 into master May 18, 2015
@jantimon jantimon deleted the 1.4.0 branch May 18, 2015 15:57
@lock
Copy link

lock bot commented May 31, 2018

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants