Javascript 禁止webpack注入CSS/Autoprefixer不工作
新的网页,但目前网页是注入样式到我的文档体,我想禁用。我不知道如何做到这一点 这是我的webpack.config.jsJavascript 禁止webpack注入CSS/Autoprefixer不工作,javascript,webpack,webpack-style-loader,Javascript,Webpack,Webpack Style Loader,新的网页,但目前网页是注入样式到我的文档体,我想禁用。我不知道如何做到这一点 这是我的webpack.config.js var webpack = require('webpack'); var autoprefixer = require('autoprefixer'); var ExtractTextPlugin = require("extract-text-webpack-plugin"); module.exports = { output: { filen
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
output: {
filename: 'bundle.js'
},
entry: {
app: './js/app.js'
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({use:[{loader: 'css-loader', options: {importLoaders: 1}}, 'postcss-loader', 'sass-loader']})
}
]
},
plugins: [
new ExtractTextPlugin('styles.css'),
new webpack.LoaderOptionsPlugin({options: {
context: __dirname,
postcss: [
autoprefixer
]
}})
]
};
html输出为
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="/wp-content/themes/index/styles.css">
<style type="text/css">
body {
background-color: black; }
h1 {
color: #fff; }
p {
display: flex;
color: #fff; }
</style>
<style type="text/css"></style>
</head>
<body>
<h1>Test</h1>
<p>Test</p>
<script src="/wp-content/themes/index/dist/bundle.js"></script>
</body>
</html>
_test.scss
h2 {
color: blue;
}
您的配置需要解决三个问题 首先,应将
模块
中的加载程序
属性重命名为规则
。您现在使用的方式是webpack 1的正确方式,webpack 2+使用规则
其次,LoaderOptionsPlugin
用于从Webpack1迁移到Webpack2。你可以读到它
将选项附加到postss加载器的新推荐方法如下所示
{
loader: 'postcss-loader',
options: {
plugins: [autoprefixer()]
}
}
有了上述配置,您的css应该有前缀,您可以安全地从插件
数组中删除webpack.LoaderOptionsPlugin
最后,如果您上面提供的信息是正确的,\u test.scss
不包括在最终捆绑包中,因为在main.scss
中
@import 'test';
将其更改为import\u test
,您将看到它包含在捆绑包中。Euuuh。。。您只有一个加载程序,这是一个scss加载程序。。。你到底在期待什么?
@import 'test';