According to the documentation, CSS file should just be import
ed.
I am just starting with webpack
and tried to import a CSS file but I get a message about a module missing:
D:Dropboxdevjekylllog>webpack --display-error-details
Hash: 0cabc1049cbcbdb8d134
Version: webpack 2.6.1
Time: 74ms
Asset Size Chunks Chunk Names
build.js 2.84 kB 0 [emitted] main
[0] ./webpack/entry.js 47 bytes {0} [built]
ERROR in ./webpack/entry.js
Module not found: Error: Can't resolve 'navbar.css' in 'D:Dropboxdevjekylllogwebpack'
resolve 'navbar.css' in 'D:Dropboxdevjekylllogwebpack'
Parsed request is a module
using description file: D:Dropboxdevjekylllogpackage.json (relative path: ./webpack)
Field 'browser' doesn't contain a valid alias configuration
after using description file: D:Dropboxdevjekylllogpackage.json (relative path: ./webpack)
resolve as module
D:Dropboxdevjekylllogwebpack
ode_modules doesn't exist or is not a directory
D:Dropboxdevjekyll
ode_modules doesn't exist or is not a directory
D:Dropboxdev
ode_modules doesn't exist or is not a directory
D:Dropbox
ode_modules doesn't exist or is not a directory
D:
ode_modules doesn't exist or is not a directory
looking for modules in D:Dropboxdevjekylllog
ode_modules
using description file: D:Dropboxdevjekylllogpackage.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: D:Dropboxdevjekylllogpackage.json (relative path: ./node_modules)
using description file: D:Dropboxdevjekylllogpackage.json (relative path: ./node_modules/navbar.css)
as directory
D:Dropboxdevjekylllog
ode_modules
avbar.css doesn't exist
no extension
Field 'browser' doesn't contain a valid alias configuration
D:Dropboxdevjekylllog
ode_modules
avbar.css doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:Dropboxdevjekylllog
ode_modules
avbar.css.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
D:Dropboxdevjekylllog
ode_modules
avbar.css.json doesn't exist
[D:Dropboxdevjekylllogwebpack
ode_modules]
[D:Dropboxdevjekyll
ode_modules]
[D:Dropboxdev
ode_modules]
[D:Dropbox
ode_modules]
[D:
ode_modules]
[D:Dropboxdevjekylllog
ode_modules
avbar.css]
[D:Dropboxdevjekylllog
ode_modules
avbar.css]
[D:Dropboxdevjekylllog
ode_modules
avbar.css.js]
[D:Dropboxdevjekylllog
ode_modules
avbar.css.json]
@ ./webpack/entry.js 1:0-21
webpack
is ran against the following webpack.config.js
:
const path = require('path');
module.exports = {
entry: path.join(__dirname, 'webpack/entry.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: 'build.js'
},
module: {
loaders: [
{
test: /.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
],
rules: [{
test: /.css$/,
use: [ 'style-loader', 'css-loader' ]
}]
}
}
I initially thought (before using --display-error-details
) that this was due to some problems with the path structure (specifically forward vs. backward slashes) but then moved navbar.css
into the root of the folder webpack
- same issue.
The detailed error shows that the CSS file is sought after in nodes_module
(which is hunted down though all the directories tree). Why? How should I then import a file which is in webpack/static/css/myfile.css
relative to the location of webpack.config.js
?
Note: the same issue exists when trying require
instead of import
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…