Preact-cli: How to add custom webpack alias ?

Created on 21 Aug 2017  路  12Comments  路  Source: preactjs/preact-cli

How to add custom webpack alias using "preact.config.js" ?

Most helpful comment

Just place that after all in the first one and you can change both :)

All 12 comments

https://ant.design/docs/react/use-with-create-react-app
I'm switch from cra -> preact-cli
I dont know how to add config to modify less-loader ? pleace help me

@cuduy197

To add a alias you need to create a preact.config.js and do something like this:

export default (config, env, helpers) => {
  const alias =  config.resolve.alias;

  alias['your-alias'] = 'pathtoyourFile.js';
};

@SaraVieira Thanks you 馃憤 , how can i config less-loader ?

Trying to check that now :)

@cuduy197 Here you go man

  const loaders = config.module.loaders;
  const lessloader = helpers
    .getLoadersByName(config, 'proxy-loader')
    .filter(loader => loader.loader.options.loader === 'less-loader')[0].loader
    .options;

  lessloader.options['youroption'] = 'stuff';

Just place that after all in the first one and you can change both :)

@SaraVieira WOW, Thanks you alot <3

@cuduy197 Worked fine ? :)

Yeah 馃槃

Awesome !

@reznord @developit can you guys close this issue ? :)

Thanks @SaraVieira

for future devs

export default function(config, env, helpers) {
  // Additional top-level alias
  config.resolve.alias = Object.assign(
    {},
    {
      components: resolve(__dirname, "src/components/"),
      global: resolve(__dirname, "src/global/"),
      routes: resolve(__dirname, "src/routes/")
    },
    config.resolve.alias
  );
}
Was this page helpful?
0 / 5 - 0 ratings