Skip to content

Commit 589201b

Browse files
committed
with css-loader v5.2.7
1 parent 468fcf5 commit 589201b

File tree

9 files changed

+7510
-1
lines changed

9 files changed

+7510
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# webpack-build-css-with-bug
2-
Sample project to show a bug
2+
Sample project to show a css-loader bug.

assets/img/shapes.svg

Lines changed: 17 additions & 0 deletions
Loading

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
<link rel="stylesheet" href="./assets/css/main-799.css">
9+
</head>
10+
<body>
11+
12+
<div class="box"></div>
13+
14+
<script src="./assets/js/main-df5.js"></script>
15+
</body>
16+
</html>

package-lock.json

Lines changed: 7360 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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "JS and CSS assets",
3+
"scripts": {
4+
"build:dev": "webpack --mode development",
5+
"build": "webpack --mode production"
6+
},
7+
"devDependencies": {
8+
"@babel/core": "^7.15.5",
9+
"@babel/preset-env": "^7.15.6",
10+
"babel-loader": "^8.2.2",
11+
"clean-webpack-plugin": "^4.0.0",
12+
"css-loader": "^5.2.7",
13+
"file-loader": "^5.1.0",
14+
"sass": "^1.41.1",
15+
"sass-loader": "^12.1.0",
16+
"webpack": "^5.53.0",
17+
"webpack-bundle-tracker": "^1.3.0",
18+
"webpack-cli": "^4.8.0"
19+
},
20+
"dependencies": {
21+
"mini-css-extract-plugin": "^2.3.0"
22+
}
23+
}

src/js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../scss/styles.scss';

src/scss/styles.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
body {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
height: 90vh;
6+
}
7+
.box {
8+
background: url(../../assets/img/shapes.svg) no-repeat;
9+
background-size: cover;
10+
width: 180px;
11+
height: 200px;
12+
}

webpack.config.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const path = require('path');
2+
const BundleTracker = require('webpack-bundle-tracker');
3+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4+
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
5+
6+
const bundlePath = __dirname + "/assets/";
7+
8+
module.exports = {
9+
entry: {
10+
main: "./src/js/index.js",
11+
},
12+
output: {
13+
path: bundlePath,
14+
filename: "js/[name]-[contenthash:3].js",
15+
},
16+
17+
module: {
18+
rules: [
19+
{
20+
test: /\.js$/,
21+
exclude: /node_modules/,
22+
use: {
23+
loader: "babel-loader",
24+
}
25+
},
26+
{
27+
test: /\.(sa|sc|c)ss$/,
28+
29+
use: [
30+
MiniCssExtractPlugin.loader,
31+
"css-loader",
32+
{
33+
loader: "sass-loader",
34+
options: {
35+
implementation: require("sass")
36+
}
37+
}
38+
]
39+
},
40+
{
41+
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
42+
use: [
43+
{
44+
loader: 'file-loader',
45+
options: {
46+
emitFile: false,
47+
publicPath: (url, resourcePath, context) => {
48+
console.log(`------ ${url}`);
49+
const cssBundleDir = bundlePath + 'css/';
50+
const fileBundleDir = path.dirname(resourcePath);
51+
const relativeFileDir = path.relative(cssBundleDir, fileBundleDir);
52+
53+
// resolves file relative path
54+
// return the new relative file path (works for images and files)
55+
return path.join(relativeFileDir, path.basename(resourcePath));
56+
}
57+
},
58+
},
59+
],
60+
}
61+
]
62+
},
63+
64+
plugins: [
65+
new CleanWebpackPlugin({
66+
cleanOnceBeforeBuildPatterns: [],
67+
cleanAfterEveryBuildPatterns: [
68+
'**/main-*',
69+
]
70+
}),
71+
new BundleTracker({
72+
indent: '\t',
73+
filename: './webpack-stats.json'
74+
}),
75+
new MiniCssExtractPlugin({
76+
filename: "css/[name]-[contenthash:3].css"
77+
})
78+
],
79+
};

0 commit comments

Comments
 (0)