问题描述
我想在较少的文件中使用内联js,但是我收到以下消息:
I would like to use inline js in my less files but I get the following message:
如何启用它?
推荐答案
我有同样的问题,我使用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
}
}]
}
我在较少编译器的源代码中找到:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!