The way my webpack is currently being set up, it places the css resources links in the head of the document, which blocks the rendering of my initial content.
<!DOCTYPE html>
<html lang="en" class="noOverflow">
<head>
<meta charset="UTF-8">
<title>title</title>
<meta name="description" content="description">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no">
<% if (htmlWebpackPlugin.options.env.isWeb) { %>
<link rel="manifest" href="/manifest.json">
<base href="/">
<% } else if (htmlWebpackPlugin.options.env.isHybrid) { %>
<script type="text/javascript" src="cordova.js"></script>
<% } %>
</head>
<body>
<noscript>How do we put this.. Your browser does not support JavaScript o_O</noscript>
<% if (htmlWebpackPlugin.options.env.isWeb) { %>
<%- require('!html-loader!./splash/splash.html') %>
<% } %>
<link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700&subset=cyrillic" rel="stylesheet">
<link rel="preload" href="<%- htmlWebpackPlugin.options.config.staticUrl %>/common/mk" as="fetch" type="application/json" crossorigin>
<link href="<%- htmlWebpackPlugin.files.chunks.app.css[0] %>" rel="stylesheet">
</body>
</html>
推荐答案
首先,我很好奇你的意图.根据提供的示例代码,您似乎主要关心的是转译 SCSS 文件,并能够将结果放入 HTML 文件中.如果您只关心这些,我建议您阅读 这篇文章.那里可能有更好的文章,但它在 Google 上排名最高,所以你去吧.
First off, I'm curious about your intent. Based on the example code provided it looks like you're mainly concerned with just transpiling an SCSS file, and being able to place the result in an HTML file. If that's all you care about I'd suggest reading this article. There may be better articles out there, but it was ranked highest on Google, so there yuh go.
If your example code was trimmed down for brevity - or you just really want to use Webpack to transpile a single SCSS file - I'd suggest you read the documentation for the options of the plugin.
But based on your comment here, and the fact that you opened this issue, I'm getting the feeling you don't want to read the documentation - so, the inject property seems to be what you need to set to false.
true ||'头'||'身体' ||假
将所有资产注入给定的 template 或 templateContent.当传递 true 或 'body' 时,所有 javascript 资源都将放置在 body 元素的底部.'head' 将脚本放在 head 元素中
Inject all assets into the given template or templateContent. When passing true or 'body' all javascript resources will be placed at the bottom of the body element. 'head' will place the scripts in the head element