yenshih / style-resources-loader

CSS processor resources loader for webpack
MIT License
262 stars 10 forks source link

How do I set in CRA with craco? #54

Open CoderAWei opened 2 years ago

CoderAWei commented 2 years ago

I want to auto import less variables in all files, but fails. Here are my settings:

// craco.config.js
module.export = {
  plugins: [
    {
       plugin: styleResourcesLoader,
       options: {
         patterns: path.resolve(__dirname, './src/styles/variables.less')
       }
    }
  ]
}

It doesn't work! How can I fix it? Thanks!!!!

candy4290 commented 2 years ago

same question!!!help!!! @CoderAWei I do like this: configure: webpackConfig => { const loaders = webpackConfig.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf; loaders.push({ test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader', { loader: 'style-resources-loader', options: { patterns: [ path.resolve(__dirname, 'src/styles/_variable.less'), ], injector: 'append' } }] }) return webpackConfig } It doesn't work too!

candy4290 commented 2 years ago

I want to auto import less variables in all files, but fails. Here are my settings:

// craco.config.js
module.export = {
  plugins: [
    {
       plugin: styleResourcesLoader,
       options: {
         patterns: path.resolve(__dirname, './src/styles/variables.less')
       }
    }
  ]
}

It doesn't work! How can I fix it? Thanks!!!!

module.exports = {
 plugins: [
   {
     plugin: CracoLessPlugin,
     options: {
       modifyLessRule: (lessRule) => {
         console.log(JSON.stringify(lessRule))
         lessRule.use.push({
           loader: 'style-resources-loader',
           options: {
               patterns: path.resolve(__dirname, 'src/styles/_variable.less'),
               injector: 'append'
           }
         })
         return lessRule
       },
       lessLoaderOptions: {
         lessOptions: {
           javascriptEnabled: true,
         },
       },
     },
   },
 ]
}