Skip to content

feat: add option to enable/disable HMR (options.hmr)#264

Merged
alexander-akait merged 1 commit into
webpack:masterfrom
drawyan:master
Sep 14, 2017
Merged

feat: add option to enable/disable HMR (options.hmr)#264
alexander-akait merged 1 commit into
webpack:masterfrom
drawyan:master

Conversation

@drawyan
Copy link
Copy Markdown
Contributor

@drawyan drawyan commented Sep 8, 2017

@jsf-clabot
Copy link
Copy Markdown

jsf-clabot commented Sep 8, 2017

CLA assistant check
All committers have signed the CLA.

Comment thread options.json Outdated
"convertToAbsoluteUrls": {
"type": "boolean"
},
"disableHMR": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

disableHMR => hmr || hot (with default true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread README.md Outdated
|**`insertInto`**|`{String}`|`<head>`|Inserts `<style></style>` into the given position|
|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
|**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled|
|**`disableHMR`**|`{Boolean}`|`false`|Avoids outputting the unnecessary Hot Module Replacement code block, good for non local development distribution|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

|**`hmr || hot`**|`{Boolean}`|`true`|Enable/disable Hot Module Replacement (HMR), if disabled no HMR Code will be added (good for non local development/distribution)|

Add it as the first item in the options table please (above base)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread README.md Outdated
}
```

### `disableHMR`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

disableHMR => hmr || hot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread README.md Outdated

### `disableHMR`

When bundling for non development environment distribution, turn this option on to avoid outputting unnecessary Hot Module Replacement code block.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reword this sentence please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@michael-ciniawsky michael-ciniawsky added this to the 0.19.0 milestone Sep 8, 2017
@michael-ciniawsky michael-ciniawsky self-assigned this Sep 8, 2017
@michael-ciniawsky michael-ciniawsky changed the title feat: introduce disableHMR option to avoid outputting unnecessary H… feat: add option to enable/disable HMR (options.hmr) Sep 8, 2017
@michael-ciniawsky
Copy link
Copy Markdown
Contributor

@drawyan Please also add a test for this

@drawyan drawyan force-pushed the master branch 2 times, most recently from a7013ca to 6d494cf Compare September 11, 2017 19:06
@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 11, 2017

@michael-ciniawsky New patch set updated, sorry for the delay of the weekend. Many thanks for the review!

@drawyan drawyan closed this Sep 11, 2017
@drawyan drawyan reopened this Sep 11, 2017
@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 11, 2017

Sorry, accidentally closed it.

Comment thread index.js Outdated

validateOptions(require('./options.json'), options, 'Style Loader')

options.hot = typeof options.hmr === 'undefined' ? options.hot : options.hmr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use only one option? Example, i think hmr is better, because hot property is part of hmr (and can be misleading).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread index.js Outdated

options.hot = typeof options.hmr === 'undefined' ? options.hot : options.hmr;

var hmrBlock = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmrBlock => hmr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread README.md Outdated
|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
|**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled|

### `hmr || hot`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😛 || (OR) :D. Let's proceed with hot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@michael-ciniawsky
Copy link
Copy Markdown
Contributor

michael-ciniawsky commented Sep 12, 2017

Or hmr (just saw the review from @evilbottnawi) depending on majority, but in any case just one property please :)

@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 12, 2017

OK, I'll go with hmr

@drawyan drawyan force-pushed the master branch 2 times, most recently from 1d94470 to 2a07baa Compare September 12, 2017 14:09
Copy link
Copy Markdown
Contributor

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

@drawyan Thx

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good! Some remarks.

Comment thread index.js Outdated
" // When the module is disposed, remove the <style> tags",
" module.hot.dispose(function() { update(); });",
"}"
options.hmr ? hmr : ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To avoid breaking changes set by default to true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ohh 😲 good catch. Yep it must be true by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is already handled by the options.json's default value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also my unit test covers the default case by not having any values for this option and it won't break because the ajv handles the default value from options.json correctly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

options.hmr = options.hmr || true (L19+) it shouldn't be mandatory to set this in webpack.config.js and it would be a breaking change aswell then. And please remove the default: true in case it causes a ValidationError for

{
   loader: 'style-loader',
   options: {}
},
{
   loader: 'style-loader',
   options: {
      other: option
   }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done and updated.

Comment thread README.md Outdated
### `hmr`

Enable/disable Hot Module Replacement (HMR), if disabled no HMR Code will be added.
This could be used for non local development and distribution.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think better to use production, distribution is misleading. distribution can be source and minified

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread index.js Outdated

validateOptions(require('./options.json'), options, 'Style Loader')

var hmr = [
Copy link
Copy Markdown
Member

@alexander-akait alexander-akait Sep 12, 2017

Choose a reason for hiding this comment

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

Let's return the name hmrBlock. hmr is option, hmrBlock is code block for hmr.

Copy link
Copy Markdown
Contributor

@michael-ciniawsky michael-ciniawsky Sep 12, 2017

Choose a reason for hiding this comment

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

The Block doesn't add any semantic meaning, it's already indicated by {Array}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@michael-ciniawsky hmrCode or hmrSource?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just hmr as there isn't anything to distinguish from (atm). Only options.hmr (The Options) && hmr (The Code), The fact that it's a block ({Array} Type) and it is Source Code is already fulfilled 😛 , it just needs a name. hmrCode is also fine, but it's not really needed imho

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@michael-ciniawsky I think better using different variable names, even if they are stored in different places, it makes the reading easier not to be misleading, also when using destructuring it helps to avoid accidentally overriding the variable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll just leave as is for now

Copy link
Copy Markdown
Contributor

@michael-ciniawsky michael-ciniawsky Sep 12, 2017

Choose a reason for hiding this comment

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

if, agreed. Still const { code } = hmr with hmr as the 'container/wrapper' then ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, hmr being a wrapper seems overkill here, but I do agree that it shouldn't be hmr to differentiate from the option's key, and this is why I put hmrBlock to indicate it's a code block. But as @michael-ciniawsky pointed out block being a bit confusing, I would say hmrCode is my pick. Updated.

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Comment thread index.js
var options = loaderUtils.getOptions(this) || {};

validateOptions(require('./options.json'), options, 'Style Loader')
options.hmr = typeof options.hmr === 'undefined' ? true : options.hmr;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use short-circuit here (options.hmr = options.hmr || true)

Copy link
Copy Markdown
Contributor

@michael-ciniawsky michael-ciniawsky Sep 12, 2017

Choose a reason for hiding this comment

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

and space (\n) [L18]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand how options.hmr = options.hmr || true is going to work. We'll never be able to set this flag to false, right?

@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 12, 2017

@evilebottnawi I've updated other files, but not sure how to test them.

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, maybe we can use mock for testing this?

@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 13, 2017

@evilebottnawi Mocked and updated, please review again. Thanks!

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Great! Thanks!

@drawyan
Copy link
Copy Markdown
Contributor Author

drawyan commented Sep 13, 2017

When will this be merged and released? My project is actually dependent on this. Thanks!

@alexander-akait alexander-akait merged commit 378e906 into webpack:master Sep 14, 2017
@alexander-akait
Copy link
Copy Markdown
Member

alexander-akait commented Sep 14, 2017

@drawyan I near future we release new version, thank you!

@RSNara
Copy link
Copy Markdown

RSNara commented Dec 1, 2017

This is really awesome! Thanks so much for this feature. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants