我不知道如何使用webpack从node_modules库中加载任何CSS,例如我已经安装了leaflet,并且每次尝试加载leaflet/dist/leaflet.css
都失败了。
能否提供一个示例,如何从node_modules加载静态样式?
我的当前webpack配置如下。此外,我正在使用extract-text-webpack-plugin
和sass-loader
,我的项目scss文件工作正常,我也有css-loader
,我是否需要解析静态css文件或者在stylePathResolves
中添加一些内容?
//require('leaflet/dist/leaflet.css');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpack = require("webpack");
var path = require('path');
var stylePathResolves = (
'includePaths[]=' + path.resolve('./') + '&' +
'includePaths[]=' + path.resolve('./node_modules')
)
module.exports = {
entry: ".js/app.js",
output: {
path: "./static/js",
filename: "app.js"
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style',
'css' + '!sass?outputStyle=expanded&' + stylePathResolves
)
}
]
},
plugins: [new ExtractTextPlugin("app.css")]
};
如何加载leaflet.css文件?如果注释掉require('leaflet/dist/leaflet.css')
,会出现以下错误:
home/myproj/node_modules/leaflet/dist/leaflet.css:3
.leaflet-map-pane,
^
SyntaxError: Unexpected token .