D
D
discoder2018-01-02 17:36:39
JavaScript
discoder, 2018-01-02 17:36:39

How to add autoprefixer for LESS inside .vue files in webpack.config?

Good afternoon colleagues.
I have several vue components inside which I use LESS to set rules for styles. I have a webpack.config for a project build.
While working on the vue-loader, I pass the code inside the LESS file through three more loaders: vue-style-loader!css-loader!less-loader.
The code

{
            test: /\.vue$/,
            loader: 'vue-loader',
            options: {
                loaders: {
                    'less': 'vue-style-loader!css-loader!less-loader'
                }
            }
        }

QUESTION: How to add an Autoprefixer for LESS at the stage of resolving .vue components?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
discoder, 2018-01-04
@discoder

Like this
1. npm i --save-dev postcss-loader
2. Create a config file - postcss.config.js

module.exports = {
  parser: 'sugarss',
  plugins: {
    'postcss-import': {},
    'postcss-cssnext': {},
    'cssnano': {}
  }
}

3. Adding a line from webpack.cinfig.js
'less': 'vue-style-loader!css-loader!postcss-loader!less-loader'

A
Alexander Taratin, 2018-01-02
@Taraflex

Now I’m being bombarded with pissing rags, but:
If you don’t use scoped styles (and there will be no reason to use them if you add short (1-3 letters) “package” prefixes to component names and observe bam), then I recommend refusing to place styles through style tag inside the component, and pull up styles via require or import at the beginning of the script tag.
The main reason is the strange connection order. Especially delivers hemorrhoids when some of the styles are already connected via require or import.
Yes, and setting up loaders for sass/less is easier this way.

A
Alexander Pushkarev, 2018-01-02
@AXP-dev

Use laravel mix. There is a convenient API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question