for example, if I want to add require("index.less") to all files and ignore this line if the file does not exist. how to do it (including, for example, using bootloaders).
require("index.less")
What I ended up with was improving the bootloader import to add an option to import a less file for each jsx file using the same name if it exists.
less
jsx
My improved import loader : https://github.com/welldone-software/imports-loader
import loader
Stretch Request: https://github.com/webpack/imports-loader/pull/12
For example, removing mainview.less in the same directory as mainview.jsx will add require("mainview.less") imports to the top of the jsx file:
mainview.less
mainview.jsx
require("mainview.less")
loaders: [ { test: /\.jsx?$/, loaders: ['imports?null=[./{name}.less]', 'react-hot', 'babel'] }, { test: /\.less$/, loader: 'style!css!less' } ]
One option is to configure require.context , and then check if the file exists against this.
Tough idea:
var req = require.context('./', false, /^index.less$/); if(req.keys().includes('./index.less')) { req('./index.less'); }