customize-cra icon indicating copy to clipboard operation
customize-cra copied to clipboard

loader cause PostcssPlugins doesn't work

Open yuyeqianxun opened this issue 4 years ago • 6 comments

I recently user 'style-resources-loader' cause some plugins not work. I'm not sure where problem it is.

addPostcssPlugins([
    require('postcss-px-to-viewport')({
      ...
    })
  ]),
  addWebpackModuleRule(
    {
      test: /\.less$/,
      use: ['style-loader', 'css-loader', 'less-loader', {
        loader: 'style-resources-loader',
        options: {
            patterns: [
                './src/global/*.less'
            ]
        }
      }]
    }
  ),

or you can use 'postcss-px2rem', it also doesn't work.

yuyeqianxun avatar May 10 '20 11:05 yuyeqianxun

I am sorry here again,I test them in another project in vue-cli. 'postcss-px-to-viewport' and 'style-resources-loader' can work together.

yuyeqianxun avatar May 10 '20 11:05 yuyeqianxun

Did you find methods?

luchanan avatar Jul 01 '20 15:07 luchanan

Did you find methods?

No,I run eject finally,or you can try another solution craco recommended by antd;

yuyeqianxun avatar Jul 02 '20 13:07 yuyeqianxun

I found anohter method:

const { override, addLessLoader, addPostcssPlugins} = require('customize-cra')
module.exports = {
  webpack: override(
    addLessLoader({
      lessOptions: {
        javascriptEnabled: true,
        modifyVars: {
          'hack': `true; @import "~@/assets/less/var.less";`
        }
      }
    }),
    addPostcssPlugins([
      require('postcss-px-to-viewport')({
        viewportWidth: 375
      })
    ])
  )
}

Attention, if addLessLoader behind addPostcssPlugins, it won't be work

luchanan avatar Jul 03 '20 07:07 luchanan

I update version to 'v1.0.0', it's work!

  addLessLoader({
            javascriptEnabled: true,
            modifyVars: {
                hack: `true; @import "~@/assets/styles/mixin.less";`,
            },
            cssLoaderOptions: {}, // .less file used css-loader option, not all CSS file.
            localIdentName: '[local]_[hash:base64:5]',
            cssModules: true,
        }),

juliana-zhu avatar Jul 31 '20 06:07 juliana-zhu

Did you find methods?

changguilei avatar Jun 19 '23 18:06 changguilei