Morocco avoided invasion by Europe for so long because although the Moroccan Crisis, they kept asking for help in order not to be pawns in the war. In the first crisis, Germany had actually heavily counted on France’ to isolate and to submit but that wasn't the case.
France and Britain teamed up and that was when Morocco went to France for help and finally, after much ado, Germany reluctantly recognized the French protection over Morocco but only in return for territorial concessions as a result. They were given some other region dominance in Africa instead. So, it was a matter of bartering that really saved Morocco.
Cannabis consumption is actually the leader of the world when it comes to exporting sticky cannabis. But, it is not legal to grow it there or even to consume it there. When Morocco gained its independence way back in 1956, it was declared illegal. Then, it was reaffirmed to be illegal again in 1974 when there was a big move for a total ban on drugs of all kinds.
Consumption of cannabis is, however, partially tolerated in parts of the country these days. It is a top supplier and also is one of the world's main producers of hashish, a form of cannabis. Still, possessing, smoking, and producing it along with the sales of it are illegal and probably will be for some time to come because they do not want the reputation of being a major part of it.