Mur*_*ock 5 javascript webpack webpack-dev-server webpack-style-loader yarnpkg
我有以下 css 文件:
<link rel="stylesheet" href="style/select.css">
<link rel="stylesheet" href="style/site.css">
Run Code Online (Sandbox Code Playgroud)
以及以下 webpack 配置
var path = require("path");
module.exports = {
entry: {
app: './src/index.js'
},
output: {
path: path.resolve(__dirname + '/dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
'style-loader',
'css-loader',
]
},
{
test: /\.html$/,
exclude: /node_modules/,
loader: 'file-loader?name=[name].[ext]',
},
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
loader: 'elm-webpack-loader?verbose=true&warn=true',
options: {debug: true, warn: true},
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
],
noParse: /\.elm$/,
},
devServer: {
inline: true,
stats: { colors: true }
},
resolve: {
mainFields: [ 'main'],
}
};
Run Code Online (Sandbox Code Playgroud)
当我使用 webpack-dev-server 时,内存文件服务器似乎具有正确的 css 文件。然而当我打电话时
纱线结构
它不会复制我的 dist 文件夹中的 css 文件,因此无法加载 css 文件。
小智 1
您是否在模块中导入 css 文件?我认为您需要使用 ExtractTextWebpackPlugin将js 包中的 css 提取到单独的 css 文件中。
但这不适用于 webpack-dev-server,因此您需要在用于开发服务器的配置中禁用该插件。有一个选项可以让您执行此操作:
new ExtractTextPlugin({
filename: '[name].css',
disable: true,
}),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5391 次 |
| 最近记录: |