I have a situation where I need to get the CSS string generated from a SASS file which has been compiled in JavaScript.
(我有一种情况,我需要获取从用JavaScript编译的SASS文件生成的CSS字符串。)
I have got a solution working with just CSS, using raw-loader
(我有一个使用raw-loader的仅使用CSS的解决方案)
https://github.com/webpack-contrib/raw-loader
(https://github.com/webpack-contrib/raw-loader)
Using the following code...
(使用以下代码...)
import css from '!!raw-loader!../css/styles.css';
console.log(css);
However for this I need to compile the SCSS manually before I do this step which I don't really want to do.
(但是,为此,在执行此步骤之前,我确实不需要手动编译SCSS。)
I would prefer to do something like this... notice it is an SCSS rather than CSS file
(我宁愿做这样的事情...请注意,这是一个SCSS而不是CSS文件)
import css from '!!raw-loader!../css/styles.scss';
console.log(css);
But this returns some JavaScript instead, I already have a SCSS loader in my webpack config which looks like this.
(但这返回了一些JavaScript,我的webpack配置中已经有一个SCSS加载器,如下所示。)
{
test: /.s[ac]ss$/i,
use: [
{
loader: 'style-loader',
options: {
insert: 'head', // insert style tag inside of <head>
injectType: 'singletonStyleTag' // this is for wrap all your style in just one style tag
}
},
'css-loader',
'sass-loader'
]
},
ask by user3284707 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…