Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #39 from vagusX/master
Browse files Browse the repository at this point in the history
fix: using webpack4
  • Loading branch information
shepherdwind authored Mar 27, 2018
2 parents 1df37c6 + c629dd5 commit 88ba1b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions examples/ts-example/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>css hot loader example</title>

<link rel="stylesheet" href="output.css">
</head>
<body>

<!-- React stuff -->
<div id="root"> hello world</div>
<div class="bar">hello world bar</div>

<script src="output.js"></script> <!-- webpack javascript output -->
</body>
</html>

2 changes: 1 addition & 1 deletion examples/webpack4/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin'); // requ

let config = { // config object
entry: {
output: ['css-hot-loader/hotModuleReplacement', './src/index.js'], // entry file
output: ['./src/index.js'], // entry file
},
output: { // output
path: path.resolve(__dirname, 'dist'), // ouput path
Expand Down
3 changes: 2 additions & 1 deletion loader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const loaderUtils = require('loader-utils');
const defaultOptions = {
fileMap: '{fileName}',
Expand All @@ -13,7 +14,7 @@ module.exports = function(content) {
return content + `
if(module.hot) {
// ${Date.now()}
var cssReload = require(${loaderUtils.stringifyRequest(this, require.resolve('./hotModuleReplacement'))})(module.id, ${JSON.stringify(options)});
var cssReload = require(${loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'hotModuleReplacement.js'))})(module.id, ${JSON.stringify(options)});
module.hot.dispose(cssReload);
module.hot.accept(undefined, cssReload);
}
Expand Down

0 comments on commit 88ba1b9

Please sign in to comment.