Skip to content

Commit c09e3ed

Browse files
committed
0 parents  commit c09e3ed

File tree

9 files changed

+5346
-0
lines changed

9 files changed

+5346
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Demo of https://github.com/webpack-contrib/mini-css-extract-plugin/pull/531
2+
3+
* `npm ci`
4+
* `npm run start`
5+
* Go to `http://localhost:8080/`
6+
* Edit `src/style.css`
7+
* Exception should happen:
8+
9+
```
10+
Uncaught TypeError: Cannot read property 'some' of null
11+
at getReloadUrl (hotModuleReplacement.js:129)
12+
at eval (hotModuleReplacement.js:145)
13+
at NodeList.forEach (<anonymous>)
14+
at reloadStyle (hotModuleReplacement.js:140)
15+
at update (hotModuleReplacement.js:194)
16+
at functionCall (hotModuleReplacement.js:24)
17+
```
18+
19+
Why?
20+
21+
* `document.currentScript` is absent due to preload
22+
* Last script is not our script, because page has `<script>` without `src` in the end of page
23+
* `getCurrentScriptUrl` returns `null`

package-lock.json

Lines changed: 5236 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "mini-css-extract-plugin-demo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack-dev-server",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"css-loader": "^3.5.3",
14+
"html-webpack-plugin": "^4.3.0",
15+
"mini-css-extract-plugin": "^0.9.0",
16+
"webpack": "^4.43.0",
17+
"webpack-cli": "^3.3.11",
18+
"webpack-dev-server": "^3.11.0"
19+
}
20+
}

src/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let div = document.createElement('div');
2+
document.body.appendChild(div);
3+
4+
// My page have <script> without `src` in the bottom
5+
let script = document.createElement('script');
6+
document.body.appendChild(script);
7+
8+
import(/* webpackChunkName: 'with-preload' */ './with-preload.js');
9+
10+
if (module.hot) {
11+
module.hot.accept('./with-preload.js');
12+
}

src/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div {
2+
display: inline-block;
3+
width: 200px;
4+
height: 200px;
5+
background: red;
6+
/* Uncomment next line for HMR: */
7+
/* background: green; */
8+
}

src/with-css.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './style.css';
2+
3+
console.log('with css');

src/with-preload.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Wait for `webpackPreload` finish
2+
// to break `document.currentScript`
3+
// Maybe it's not strictly required
4+
setTimeout(() => {
5+
import(
6+
/* webpackChunkName: 'with-css', webpackPreload: true */ './with-css.js'
7+
);
8+
}, 100);

webpack.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const _path = require('path');
2+
const { HotModuleReplacementPlugin } = require('webpack');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5+
6+
module.exports = {
7+
plugins: [new MiniCssExtractPlugin()],
8+
entry: _path.join(__dirname, 'src/main.js'),
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/i,
13+
use: [
14+
{
15+
loader: MiniCssExtractPlugin.loader,
16+
options: {
17+
hmr: true,
18+
},
19+
},
20+
'css-loader',
21+
],
22+
},
23+
],
24+
},
25+
plugins: [
26+
new MiniCssExtractPlugin(),
27+
new HotModuleReplacementPlugin(),
28+
new HtmlWebpackPlugin({
29+
title: 'mini-css-extract-plugin demo',
30+
}),
31+
],
32+
devServer: {
33+
hotOnly: true,
34+
},
35+
};

0 commit comments

Comments
 (0)