在LESS中启用内联javascript [英] Enable inline javascript in LESS

查看:1191
本文介绍了在LESS中启用内联javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在较少的文件中使用内联js,但是我收到以下消息:

I would like to use inline js in my less files but I get the following message:


未启用内联JavaScript。它是否在您的选项中设置?

Inline JavaScript is not enabled. Is it set in your options?

如何启用它?

推荐答案

我有同样的问题,我使用webpack少加载器,我需要在较少的加载器配置中添加javascript选项:

I had same problem, I use webpack with less loader, I needed to add javascript option in less loader config:

{
        test: /\.less$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "less-loader",
            options: {
                javascriptEnabled: true
            }
        }]
}

我在较少编译器的源代码中找到: https://github.com/less/less.js/blob/3。 x / bin / lessc

I found in the sourcecode of less compiler: https://github.com/less/less.js/blob/3.x/bin/lessc

以这种方式解析js less选项:

that they parse js less option in this way:

        case 'js':
            options.javascriptEnabled = true;
            break;
        case 'no-js':
            console.error('The "--no-js" argument is deprecated, as inline JavaScript ' + 
                'is disabled by default. Use "--js" to enable inline JavaScript (not recommended).');
            break;

所以你应该在静态编译(命令行)或'javascriptEnabled中使用'--js' :true'在动态编译(如webpack loader)中启用javascript。

So you should probably use '--js' in a static compilation ( command line ) or 'javascriptEnabled: true' in a dynamic compilation ( like webpack loader ) to enable javascript.

这篇关于在LESS中启用内联javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆