gpt4 book ai didi

javascript - CSS 无法在 webpack 项目中立即加载

转载 作者:行者123 更新时间:2023-11-29 15:58:54 25 4
gpt4 key购买 nike

这是显示第一次加载的图像

enter image description here

微秒后,一切都很好,例如设计、javascript、图像等...

这是我的 webpack.config.js:

const path = require('path');
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
mode: 'development',

entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},

module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true }
}
]
},
{
test: /\.(scss|css)$/,
use: [
{
// Adds CSS to the DOM by injecting a `<style>` tag
loader: 'style-loader'
},
{
// Interprets `@import` and `url()` like `import/require()` and will resolve them
loader: 'css-loader'
},
{
// Loader for webpack to process CSS with PostCSS
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('autoprefixer')
];
}
}
},
{
// Loads a SASS/SCSS file and compiles it to CSS
loader: 'sass-loader'
},
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader'
]
},

]
},

plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html"
})
]
};

我不知道我错过了什么,但我知道肯定错过了一些东西但没有指出。我试过了,但没有成功。

如果能帮助我解决这个问题,我将非常感激。

谢谢

最佳答案

显然 CSS 总是在 JS 之后加载。看看this issue .

您还可以将 display: none 设置为您的 body 或 main div 并在 CSS 中更改它。加载时间相同,但您不会在那几微秒内看到样式丑陋的内容。

关于javascript - CSS 无法在 webpack 项目中立即加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55418831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com