javascriptlaravellaravel-mixless-loader

Custom less-loader in Laravel Mix


I am trying to import LESS file in my JS code. But I get error like - 'You may need an appropriate loader to handle this file type.'. Version - "laravel-mix": "^0.11.4"

In my webpack.mix.js I tried this code

mix.webpackConfig({
    module: {
        rules: [{
            test: /\.less$/,
            loader: ['style-loader','css-loader','less-loader']
        }]
    }
})........

But I still getting the same error.


Solution

  • const path = require('path');
    mix.webpackConfig({
     module: {
       rules: [
          {
            test: /\.less$/,
            loader: "style-loader!css-loader!less-loader",
            exclude: [
                path.resolve(__dirname, "node-modules"),
                path.resolve(__dirname, "resources/assets/less"),
            ],
          },
      ]} 
    })
    

    Works for my issue