Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less loader for webpack not working

Tags:

webpack

less

I'm trying to use webpack. I can't setup less loader for webpack. When i start webpack it compile js files, but not compile less. I see only "index.html" and "app.js" in dist folder after compile.

My webpack.config.js:

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        'app': './src/scripts/app'
    },
    output: {
        path: './dist',
        filename: `/app.js`,
        chunkFilename: "[id].js"
    },
    resolve: {
        modulesDirectories: ['bower_components', 'node_modules', './src'],
        fallback: ['./public']
    },
    module: {
        loaders: [
            {
                test: /\.less$/,
                loader: ExtractTextPlugin.extract(
                    'css?sourceMap!' +
                    'less?sourceMap'
                )
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin(`[name].css`, {
            allChunks: true
        }),
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ]
};

My project structure:

src
 |-index.html
 |--scripts
 | |-app.js
 |--styles
 | |-app.less
like image 996
sv1809 Avatar asked Jul 28 '26 23:07

sv1809


1 Answers

Webpack scans through your source code looking for require statements to find your files. Make sure you include require('my.less') or similar in your code.

[update] Webpack also understands ES6 module syntax, so import 'my.less' will also work if that style is your preference.

like image 141
Euan Smith Avatar answered Aug 01 '26 20:08

Euan Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!