美文网首页
在webpack中设置一个开屏loading

在webpack中设置一个开屏loading

作者: 北南桥 | 来源:发表于2019-05-21 09:08 被阅读0次

在webpack中设置初始化loading

项目基于create-react-app脚手架,所以先创建项目,然后npm run eject在config文件目录下加入loading;

1、在plugins的html模版中添加变量

    new HtmlWebpackPlugin(
                Object.assign(
                    {},
                    {
                        inject: true,
                        template: paths.appHtml,
                        // 初始化加载loading
                        // loading: {
                        //     html: `<h1 style="display: flex;width:100vw;height:100vh;justify-content: center;align-items: center;margin-top: -27vh;overflow: hidden;">LOADING...</h1>`
                        // }
                    },
                    isEnvProduction
                        ? {
                            minify: {
                                removeComments: true,
                                collapseWhitespace: true,
                                removeRedundantAttributes: true,
                                useShortDoctype: true,
                                removeEmptyAttributes: true,
                                removeStyleLinkTypeAttributes: true,
                                keepClosingSlash: true,
                                minifyJS: true,
                                minifyCSS: true,
                                minifyURLs: true,
                            },
                        }
                        : undefined
                )
            ),

2、在public的html模版中添加变量

    <!-- 首屏加载的时的loading -->
    <%= htmlWebpackPlugin.options.loading.html %>

相关文章

网友评论

      本文标题:在webpack中设置一个开屏loading

      本文链接:https://www.haomeiwen.com/subject/xbynaqtx.html