Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom webpack alias ? #330

Closed
cuduy197 opened this issue Aug 21, 2017 · 12 comments
Closed

How to add custom webpack alias ? #330

cuduy197 opened this issue Aug 21, 2017 · 12 comments

Comments

@cuduy197
Copy link

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

@cuduy197
Copy link
Author

cuduy197 commented Aug 21, 2017

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

@SaraVieira
Copy link
Contributor

@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';
};

@cuduy197
Copy link
Author

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

@SaraVieira
Copy link
Contributor

Trying to check that now :)

@SaraVieira
Copy link
Contributor

SaraVieira commented Aug 21, 2017

@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';

@SaraVieira
Copy link
Contributor

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

@cuduy197
Copy link
Author

@SaraVieira WOW, Thanks you alot <3

@SaraVieira
Copy link
Contributor

@cuduy197 Worked fine ? :)

@cuduy197
Copy link
Author

Yeah 😄

@SaraVieira
Copy link
Contributor

Awesome !

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

@reznord reznord closed this as completed Aug 21, 2017
@lukeed
Copy link
Member

lukeed commented Aug 21, 2017

Thanks @SaraVieira

@drKnoxy
Copy link

drKnoxy commented Jan 4, 2018

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
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants