Javascript CSS未在网页包项目中立即加载

Javascript CSS未在网页包项目中立即加载,javascript,webpack,Javascript,Webpack,这是显示首次加载的图像 几微秒后,一切正常,如设计、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")

这是显示首次加载的图像

几微秒后,一切正常,如设计、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"
        })
    ]
};
const path=require('path');
const webpack=require('webpack');
var HtmlWebpackPlugin=require('html-webpack-plugin');
const MiniCssExtractPlugin=require(“迷你css提取插件”);
module.exports={
模式:"发展",,
条目:'./src/index.js',
输出:{
文件名:“bundle.js”,
path:path.resolve(uu dirname,'dist')
},
模块:{
规则:[
{
测试:/\.js$/,,
排除:/node_模块/,
使用:{
加载器:“巴别塔加载器”
}
},
{
测试:/\.html$/,,
使用:[
{
加载器:“html加载器”,
选项:{minimize:true}
}
]
},
{
测试:/\(scss | css)$/,
使用:[
{
//通过注入``标记将CSS添加到DOM中
加载器:“样式加载器”
},
{
//将“@import”和“url()”解释为类似于“import/require()”,并将解析它们
加载器:“css加载器”
},
{
//网页包的加载器,用于使用PostSS处理CSS
加载器:“postss加载器”,
选项:{
插件:函数(){
返回[
需要('autoprefixer')
];
}
}
},
{
//加载SASS/SCSS文件并将其编译为CSS
加载器:“sass加载器”
},
]
},
{
测试:/\(png | svg | jpg | gif)$/,
使用:[
“文件加载器”
]
},
{
测试:/\(woff | woff2 | eot | ttf | otf)$/,
使用:[
“文件加载器”
]
},
]
},
插件:[
新HtmlWebpackPlugin({
模板:“./src/index.html”,
文件名:“./index.html”
})
]
};
我不知道我漏掉了什么,但我知道肯定漏掉了什么,但没有暗示。我试过了,但没有成功

如果你能帮我解决这个问题,我真的很感激


谢谢,显然CSS总是在JS之后加载

看看这个:


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

那么,第二次加载或“在几微秒后”可以吗?@JeremyThille在几微秒后,只需在一切正常后显示断开的屏幕那么为什么要提到“第一次加载”?这无关紧要。“微秒”延迟只是因为CSS文件尚未加载。它很快,但不是即时的。@Jeremythill谢谢你的建议,我已经更新了这个问题,你能帮我解决这个问题吗?为什么它没有立即加载?好的,我想我知道为什么(CSS还没有加载),但是如何修复它,不。。。对不起,我从未使用过网页包