I can't speak to Portugal in particular, but one strategy I've found is to simply ignore these street vendors if you don't want to buy what they are selling. Just pretend not to hear them. It helps if you are wearing earphones, even if you're not actually listening to music.
The worst thing that can happen is, as you mentioned, they may chase/harass you. Just pretend not to hear that either; just ignore them completely. Eventually they'll conclude that shouting insults at a brick wall is not the most productive use of their time and they'll go away.
This is, of course, assuming you don't actually want to buy weed, if the seller is indeed legit. If you actually do want to buy weed, you have a larger problem: Marijuana remains illegal in most places in the world (unsure about Portugal in particular), and getting caught with it, especially as a foreigner without status, can get you into very big trouble. In North America, marijuana possession is not a big deal (in Canada it's even legal!), but other countries treat drug possession very seriously. Don't put yourself in a position to get thrown in prison in a foreign country for years on end; you can give up drugs for a couple weeks while you're on vacation (and if you can't, don't go on vacation to countries where your drug of choice is not legal).