Webpack中的scsslint-hot preLoader在子目录中不起作用

凯文·H

我使用scss-lint来整理我的SCSS文件。要在Webpack中以热模式运行它,我使用scsslint-hot。

我将其添加到Webpack的preLoaders中,只要文件不嵌套在子目录中,它就可以正常工作。

例如:

./src/style/layout.scss正确LINTED。

./src/style/mixins/buttons.scss根本不会掉毛。为什么?

我究竟做错了什么?我在Google上搜索了很多,而且Webpack文档还说include应该还包括子目录。

的.scss-lint.yml仅包含规则,我已经尝试将其添加scss_files: 'src/style/**/*.scss'到yml文件中,但不能解决问题。

这是我的webpack.config.js有趣的部分:

var dir_style = path.resolve(__dirname, 'src', 'style’);

…

preLoaders: [
    {
        ...
    },
    {
        test: /\.scss$/,
        loader: 'scsslint-hot',
        include: dir_style,
        query: {
            config: '.scss-lint.yml',
            failOnError: production,
            failOnWarning: production,
        }
    }
],

也许您需要查看我完整的webpack配置,然后转到:

var webpack = require('webpack'),
    path = require('path'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    autoprefixer = require('autoprefixer'),
    cssnano = require('cssnano'),
    WebpackCleanupPlugin = require('webpack-cleanup-plugin');
    webpackFailPlugin = require('webpack-fail-plugin');

var production = process.env.NODE_ENV === 'production',
    dir_src = path.resolve(__dirname, 'src'),
    dir_js = path.resolve(dir_src, 'js'),
    dir_style = path.resolve(dir_src, 'style'),
    dir_assets = path.resolve(dir_src, 'assets'),
    dir_public = path.resolve(__dirname, 'public'),
    dir_exclude = /(node_modules|public)/;

const HOST = process.env.HOST || "127.0.0.1";
const PORT = process.env.PORT || "8888";


var plugins = [
    webpackFailPlugin,
    new webpack.HotModuleReplacementPlugin(),
    new HtmlWebpackPlugin({
        template: './src/template.html'
    })
];

if (production) {
    plugins.push(
        new webpack.NoErrorsPlugin(), // needs to be only set for production otherwise failOnErrors will be ignored

        // process.env.NODE_ENV is already set to production through "build" task in
        // package.json, but defining it again reduces file size enormous, but I don't know why
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new WebpackCleanupPlugin(),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin({
            sourceMap: false,
            mangle: true,
            compress: {
                warnings: false
            },
            output: {
                comments: false
            }
        }),
        new webpack.optimize.MinChunkSizePlugin({minChunkSize: 10000})
    );
}

module.exports = {
	entry: {
        index: path.resolve(dir_js, 'index.jsx')
    },
	output: {
		path: dir_public,
		filename: '[name]_[hash].min.js'
	},
	resolve: {
		extensions: ['', '.js', '.jsx']
	},
	module: {
        preLoaders: [
            {
                test: /\.jsx?$/,
                loader: 'eslint',
                include: dir_js
            },
            {
                test: /\.scss$/,
                loader: 'scsslint-hot',
                include: dir_style,
                query: {
                    config: '.scss-lint.yml',
                    failOnError: production,
                    failOnWarning: production,
                }
            }
        ],
		loaders: [
            {
                test: /\.jsx?$/,
                exclude: dir_exclude,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react'],
                    plugins: [
                        'transform-runtime',
                        'transform-decorators-legacy',
                        'transform-class-properties',
                        'react-hot-loader/babel'
                    ],
                    cacheDirectory: true
                }
            },
            {
                test: /\.scss$/,
                include: dir_style,
                loaders: ['style', production ? 'css' :'css?sourceMap', 'postcss', 'sass']
            },
            {
                test: /\.(png|jpe?g|gif|mp3|svg)$/,
                include: dir_assets,
                exclude: dir_exclude,
                loader: 'url-loader?limit=10000'
            }
        ]
	},
	devServer: {
		contentBase: "./public",
		// do not print bundle build stats
		noInfo: true,
		// enable HMR
		hot: true,
		// embed the webpack-dev-server runtime into the bundle
		inline: true,
		// serve index.html in place of 404 responses to allow HTML5 history
		historyApiFallback: true,
		port: PORT,
		host: HOST
	},
	plugins: plugins,
    eslint: {
        failOnWarning: production,
        failOnError: production
    },
    postcss: function () {
        return [autoprefixer({ browsers: ['last 2 versions'] }), cssnano];
    },
    debug: !production,
    devtool: production ? false : 'cheap-module-eval-source-map'
};

谢谢你的帮助!

斯切克

凯文·H

好的,两天后没有任何改变,它突然起作用了:-)

因此,这似乎只是一个缓存问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Angular Service Worker在子目录中不起作用

来自分类Dev

PHP - 包含在子目录中不起作用

来自分类Dev

子目录中的链接不起作用

来自分类Dev

子目录中的无脂肪php,路由不起作用

来自分类Dev

将/page.html重定向到/ page在子目录中不起作用

来自分类Dev

标签上的git命令自动完成在Mac的子目录中不起作用

来自分类Dev

.dockerignore在子目录上不起作用...仍在映像中结束

来自分类Dev

Nginx auth_basic并在子目录中重写不起作用

来自分类Dev

.htaccess mod_rewrite在子目录中不起作用

来自分类Dev

PHP Slim 3 .htaccess 和 index.php 在子目录中不起作用

来自分类Dev

由composer安装在子目录中的phpspreadsheet,不起作用

来自分类Dev

网关响应在子目录 wordpress install 中不起作用

来自分类Dev

为什么所有子目录中的此grep字符串都不起作用?

来自分类Dev

隐藏PHP扩展名和隐藏子目录都在一个URL中.htaccess中不起作用

来自分类Dev

如何在Express应用中设置webpack-hot-middleware?

来自分类Dev

子目录中的cakePHP

来自分类Dev

提示中的子目录?

来自分类Dev

子目录中的测试

来自分类Dev

子目录中的cakePHP

来自分类Dev

子目录中的文件?

来自分类Dev

htaccess将root重定向到子目录,但允许root中的index.php起作用

来自分类Dev

镜像SVN子目录中的git子目录

来自分类Dev

镜像SVN子目录中的git子目录

来自分类Dev

使用循环在子目录中的子目录

来自分类Dev

删除子目录中留下给定的子目录

来自分类Dev

`rhandsontable`包中的`hot_to_r()`函数在“普通” .R脚本中不起作用-如何检查闪亮数据的外观?

来自分类Dev

目录中的子目录数?

来自分类Dev

从目录中获取子目录

来自分类Dev

遍历目录中的子目录

Related 相关文章

热门标签

归档