问答详情
源自:4-5 使用 less 和 sass

为什么我的layer.js不会自动加入@import './layer/layer.less'


var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
module.exports = {
    entry:'./src/app.js',
    output:{
        path:__dirname+'/dist',
        filename:'js/[name].bundle.js'
    },
    module:{
        rules: [
            {test: /\.css$/,
                use: ['style-loader', 'css-loader', {
                    loader: 'postcss-loader',
                    options: {
                        plugins: [
                            require("autoprefixer")({browsers: ["last 5 versions"]})
                        ]
                    }
                }]
            },
            {test:/\.less$/,
                use:['style-loader','css-loader',{
                    loader:'postcss-loader',
                    options:{
                        plugins:[
                            require('autoprefixer')({
                                browsers:['last 5 versions']
                            })
                        ]
                    }
                },
                'less-loader'
                ]
            }
        ],
        loaders: [{
            test: /\.js$/,
            loader: 'babel-loader',
            exclude: path.resolve(__dirname, 'node_modules'),
            include: '/src/',
            query: {
                presets: ['es2016']
            }
        }]
    },
    plugins:[
        new HtmlWebpackPlugin({
            filename:'index.html',
            template:'index.html',
            inject:'body',
            title:'this is index.html'
        })
    ]
}

提问者:hudy 2018-02-08 11:14

个回答

  • A夜猫的兔子
    2018-05-25 19:50:06

    {

                    test:/\.css$/,

                    loader:'style-loader!css-loader?importLoaders=1!postcss-loader',  

                },

                {

                    test:/\.less$/,

                    loader:'style-loader!css-loader!postcss-loader!less-loader'

                }


    这样就可以了


  • lxd123
    2018-03-15 15:51:04

    问题解决了没有  我也是这个问题 没有引进去  layer.less


  • hudy
    2018-02-08 11:23:31

    这个@import './layer.less'应该是自动填写到layer.js内,不应该是我手动加入的,但是现在是没哟自动生成

  • 叶梓欣
    2018-02-08 11:17:29

    @import './layer.less'才对吧,你的layer.js应该和layer.less都在less文件夹中吧