【发布时间】:2016-02-19 01:55:46
【问题描述】:
在我的 webpack 项目中,我想使用 JavaScript 将样式作为 <style> 标签注入页面,而不是通过 <link> 标签引用外部文件。我目前使用style-loader作为样式,它会在头部输出一堆链接标签。
而不是这样:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/things">
<link rel="stylesheet" type="text/css" href="/things">
<link rel="stylesheet" type="text/css" href="/things">
</head>
<body>
我想要这个:
<html>
<head>
</head>
<style>
/* things here */
</style>
<body>
有没有办法做到这一点?我读过documentation,但它只提到了构建CSS输出文件,而不是以这种方式输出到样式标签。
原因:
- 我正在发布一个要通过 NPM/Bower 包含的模块,我宁愿将构建保留为单个包,而不必恢复为
- 速度更快。有很多关于最小化请求数量的文献,包括来自 webpack:https://github.com/christianalfoni/react-webpack-cookbook/wiki/Inlining-images
【问题讨论】: