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

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

Merged
merged 1 commit into from
Sep 14, 2017

Conversation

drawyan
Copy link
Contributor

@drawyan drawyan commented Sep 8, 2017

@jsf-clabot
Copy link

jsf-clabot commented Sep 8, 2017

CLA assistant check
All committers have signed the CLA.

options.json Outdated
@@ -22,6 +22,9 @@
},
"convertToAbsoluteUrls": {
"type": "boolean"
},
"disableHMR": {
Copy link
Member

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
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
@@ -141,6 +141,7 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`.
|**`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
Member

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
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
@@ -344,6 +345,21 @@ If convertToAbsoluteUrls and sourceMaps are both enabled, relative urls will be
}
```

### `disableHMR`
Copy link
Member

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
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
@@ -344,6 +345,21 @@ If convertToAbsoluteUrls and sourceMaps are both enabled, relative urls will be
}
```

### `disableHMR`

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

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
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
Member

@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
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
Contributor Author

drawyan commented Sep 11, 2017

Sorry, accidentally closed it.

index.js Outdated
@@ -17,6 +17,24 @@ module.exports.pitch = function (request) {

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

options.hot = typeof options.hmr === 'undefined' ? options.hot : options.hmr;
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Done

index.js Outdated
@@ -17,6 +17,24 @@ module.exports.pitch = function (request) {

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

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

var hmrBlock = [
Copy link
Member

Choose a reason for hiding this comment

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

hmrBlock => hmr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
@@ -142,6 +143,28 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`.
|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
|**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled|

### `hmr || hot`
Copy link
Member

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
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
Member

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
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
Member

@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
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.

index.js Outdated
" // When the module is disposed, remove the <style> tags",
" module.hot.dispose(function() { update(); });",
"}"
options.hmr ? hmr : ""
Copy link
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
Member

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
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
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
Member

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
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.

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
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
Contributor Author

Choose a reason for hiding this comment

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

Done

index.js Outdated
@@ -17,6 +17,22 @@ module.exports.pitch = function (request) {

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

var hmr = [
Copy link
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
Member

@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
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
Member

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
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
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
Member

@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
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
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.

@drawyan
Sorry, we forget about this lines:

"if(module.hot) {",

"if(module.hot) {",

if (module.hot) {

And tests

index.js Outdated
@@ -16,6 +16,23 @@ module.exports.pitch = function (request) {
var options = loaderUtils.getOptions(this) || {};

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

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
Member

@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
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
Contributor Author

drawyan commented Sep 12, 2017

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

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

drawyan commented Sep 13, 2017

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

Copy link
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
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-contrib:master Sep 14, 2017
@alexander-akait
Copy link
Member

alexander-akait commented Sep 14, 2017

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

@RSNara
Copy link

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.

None yet

6 participants