Reputation: 2374
i am trying to load a css file with webpack but i keep getting this error message as shown in the picuture.
i have done a lot of searching so please don't, all questions don't seem to fit my case.
below given are the various file am working with
{
"name": "loading_files",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^0.28.11",
"lodash": "^4.17.5",
"style-loader": "^0.21.0",
"webpack": "^4.6.0",
"webpack-cli": "^2.0.14"
}
}
"use strict"
let path = require("path");
module.exports = {
mode: "development",
entry: "./src/index.js",
output: {
filename: 'bundler.js',
path: path.resolve(__dirname, 'dist'),
},
module:{
rules: [
{
test: "/\.css$/",
use: ["style-loader", "css-loader"]
}
]
}
}
import _ from 'lodash';
import css from './index.css';
function component() {
var element = document.createElement('div');
element.innerHTML = _.join(['Hello', 'webpack'], ' ');
element.classList.add('hello');
return element;
}
document.body.appendChild(component());
.hello{
color: red;
}
am currently using webpack v4.6.0
and npm v5.0.0
Upvotes: 1
Views: 5988
Reputation: 3756
In your webpack.config.js
,
please remove the ""
from the regex
expression.
// Whatever else you got here
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
Upvotes: 2
Reputation: 1953
Your webpack config file should not have the file extension .json
.
Please change the extension to .js
Also, you need to tell webpack, that you want to use a config file and give it the path to this file. In your package.json, please modify the following prop:
{
scripts: {
"compile": "webpack --config webpack.config.js",
}
}
Upvotes: 1