Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable inline JavaScript for LESS in Nuxt.js?

Tags:

less

nuxt.js

In a Nuxt.js project, I've npm installed less and less-loader so I can have dynamic CSS for iView. However, when I try to overwrite iView's global variables, an error appears: "Inline JavaScript is not enabled. Is it set in your options?"

In Nuxt.js docs (https://nuxtjs.org/api/configuration-build#loaders) they state they have a preconfigured less loader. less: {}, so I tried...

less: {
  javascriptEnabled: true
}

and...

less: {
  options: {
    javascriptEnabled: true
  }
}

and even...

less: {
  dev: {
    options: {
      javascriptEnabled: true
    }   
  }
}

Nuxt.js seems to ignore all of this. So how should I configure it in Nuxt.js?

like image 224
Rex Factorem Avatar asked Mar 05 '26 13:03

Rex Factorem


2 Answers

Add this to your nuxt.config.js

/*
 ** Build configuration
 ** See https://nuxtjs.org/api/configuration-build/
 */
build: {
    /*
     ** You can extend webpack config here
     */
    loaders: {
        less: {
            lessOptions: {
                javascriptEnabled: true,
            },
        },
    },
},
like image 101
Sarmad Avatar answered Mar 08 '26 20:03

Sarmad


you can do it

 build: {
    /*
     ** You can extend webpack config here
     */
    extend(config, { loaders: { less } }) {
      less.javascriptEnabled = true
    }
  }
like image 44
avilang Avatar answered Mar 08 '26 19:03

avilang



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!