Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁止webpack注入CSS/Autoprefixer不工作_Javascript_Webpack_Webpack Style Loader - Fatal编程技术网

Javascript 禁止webpack注入CSS/Autoprefixer不工作

Javascript 禁止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

新的网页,但目前网页是注入样式到我的文档体,我想禁用。我不知道如何做到这一点

这是我的webpack.config.js

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';