Skip to content

Commit

Permalink
Output hot module logics on demand (#185)
Browse files Browse the repository at this point in the history
* output hot module logics on demand

* fix lint errors

---------

Co-authored-by: poying <[email protected]>
  • Loading branch information
xboy2012 and poying authored Dec 4, 2024
1 parent f30bbe7 commit f87ccc3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports.pitch = function pitch(request) {

const insertCss = require.resolve('./insertCss.js')
return `
var refs = 0;
var css = require(${stringifyRequest(this, `!!${request}`)});
var insertCss = require(${stringifyRequest(this, `!${insertCss}`)});
var content = typeof css === 'string' ? [[module.id, css, '']] : css;
Expand All @@ -27,6 +26,9 @@ module.exports.pitch = function pitch(request) {
exports._getCss = function() { return '' + css; };
exports._insertCss = function(options) { return insertCss(content, options) };
${
this.hot
? `
// Hot Module Replacement
// https://webpack.github.io/docs/hot-module-replacement
// Only activated in browser context
Expand All @@ -39,5 +41,8 @@ module.exports.pitch = function pitch(request) {
});
module.hot.dispose(function() { removeCss(); });
}
`
: ''
}
`
}

0 comments on commit f87ccc3

Please sign in to comment.