博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在react项目中配置less
阅读量:4186 次
发布时间:2019-05-26

本文共 1097 字,大约阅读时间需要 3 分钟。

如何在create-react-app创建的项目下配置less,其实很简单,只是create-react-app创建的项目没有暴露webpack相关配置,所以需要暴露出webpack相关配置,具体操作如下:

一、暴露webpack,安装less\less-loader依赖

create-react-app创建的项目下是不支持less的,我们要使用less就需要在相关配置文件中配置。

关于less的需要找到两个文件webpack.config.dev.jswebpack.config.prod.js

可是,create-react-app创建的项目是看不到webpack相关的配置文件,所以需要先暴露出来,使用以下命令:

npm run eject

安装less相关依赖

npm install less less-loader --save-dev

二、修改webpack文件配置

1、修改webpack.config.dev.js文件配置

// 在module中做了三处修改  // 第一处是找到 `test: /\.css$/` 将其改为  `test: /\.(css|less)$/`  // 第二处是增加 `less-loader`的配置  // 第三处是在exclude属性中增加 `/\.(css|less)$/`   // 具体修改如下  module: {
... {
// test: /\.css$/ 第一处 test: /\.(css|less)$/, use: [ require.resolve('style-loader'), ... // 第二处 {
loader: require.resolve('less-loader') } ] }, {
exclude: [ /\.(js|jsx|mjs)$/, /\.html$/, /\.json$/, // 第三处 /\.(css|less)$/, ] } }

2、修改webpack.config.pro.js文件配置

操作和webpack.config.dev.js相同,不再赘述~

转载自:https://www.cnblogs.com/jayxiangnan/p/9116663.html

你可能感兴趣的文章
leetcode Unique Paths II
查看>>
几个大数据的问题
查看>>
CareerCup Pots of gold game:看谁拿的钱多
查看>>
CarreerCup Sort Height
查看>>
CareerCup Sort an array in a special way
查看>>
CareerCup Find lexicographic minimum in a circular array 循环数组字典序
查看>>
CareerCup Cost of cutting wood
查看>>
Find the number of subsets such that the sum of numbers in the subset is a prime number
查看>>
CareerCup Binary Tree the Maximum of 人
查看>>
CareerCup Divide n cakes to k different people
查看>>
CareerCup Randomly return a node in a binary tree
查看>>
CareerCup Given a sorted array which contains scores. Write a program to find occurrence
查看>>
CareerCup The number of pairs (x, y) of distinct elements with condition x + y <= Threshold
查看>>
Build a key-value data structure which can perform lookup and rangeLookup(key1, key2)
查看>>
整数划分问题---动态规划、递归
查看>>
Balanced Partition
查看>>
Number of 1s
查看>>
CareerCup Find all the conflicting appointments from a given list of n appointments.
查看>>
CareerCup Given an array having positive integers, find a subarray which adds to a given number
查看>>
CareerCup Generate all the possible substrings
查看>>