项目中用了阿里iconfont自定义图标资源,当把官网下载的xxxIcon.js引入项目中时,使用craco build 构建项目报错了,报错信息如下:
src\scripts\aliIcon.js
Line 1:1: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:229330: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:229438: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:229489: Expected an assignment or function call and instead saw an expression no-unused-expressions
很明显,这是eslint语法检测报的,那就配置craro,将eslint关闭,如下:
const CracoLessPlugin = require("craco-less");
const path = require("path");
module.exports = {
// antd定义主题色
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
//自定义主题色(橙色)
modifyVars: { "@primary-color": "#FD8200" },
javascriptEnabled: true,
},
},
},
},
],
//antd组件样式按需引入
babel: {
plugins: [
[
"import",
{
libraryName: "antd",
libraryDirectory: "es",
style: true,
},
],
],
},
eslint:{
// 默认是开启的,这个关闭了,否则打包的时候会检查语法,导致阿里的xxicon.js检测报错
enable:false,
},
webpack: {
alias: {
...
},
},
};