I seem to recall that the construction of Gal representations associated to eigenforms with CM was done much before the general cases due to EichlerShimura, DeligneSerre and Deligne. Was this done by Hecke? Can someone give the exact reference? Thanks.

The idea of Galois representations attached to modular forms is one which evolved over the course of the 1960s, as far as I know. One should look at various papers of Serre from that time (available e.g. in his collected works), as well as his book on abelian $\ell$adic representations, to get a feeling for how the subject looked before it entered its "modern phase" with the work of Deligne, the ideas of Langlands, and so on. In the particular case of CM forms, these modular forms and their associated $L$functions were understood by Hecke. In particular, I believe that he knew that the $L$function of such a modular forms was precisely the $L$function of the corresponding Grossencharacter. Once one also knows about $L$functions attached to Galois representations, and the fact that they are invariant under induction, one sees that this is the same as the $L$function of the (family of $\ell$adic) Galois representation(s) attaced to the twodimensional representation of $G_{\mathbb Q}$ obtained by inducing the Grossencharacter from $G_K$ (where $K$ is the quad. imag. field of to which the Grossencharacter is attached). However, Hecke didn't think in these Galois theoretic terms, as far as I know, and although at the same time that Hecke was working (and in the same place, I think  Hamburg) Artin was inventing his $L$functions, Artin was only thinking about finite image Galois reps., not reps. of the kind obtained from general algebraic Grossencharacters or their inductions. (This lack of communication between Artin and Hecke is commented on by Tate somewhere, which is where I learned about it.) As Rob Harron points out in the comments, Weil was the one who introduced the notion of algebraic Grossencharacter. The theory was further developed in Serre's "abelian $\ell$adic representations" book, and here he carefully explains how to get compatible families of $\ell$adic representations from an algebraic Grossencharacter (and conversely, under suitable hypotheses; this converse is more or less the abelian case of what would later be called the FontaineMazur conjecture). Serre explains the relationship with CM abelian varieties, but I don't think modular forms make much of an appearance in this book. On the other hand, this book does contain the idea of $L$function of an $\ell$adic family of Galois reps., which is part of the infrastructure needed to relate Galois representations and modular (or, more generally, automorphic) forms. As for the theory of CM abelian varieties, the relationship between these and algebraic Grossencharacters was first worked out by Shimura and Taniyama in their book (I think), and probably also appears in Weil's article (as well as in Serre's book, as already noted). The fact that every CM elliptic curve is modular was proved by Shimura (in a paper in the early 70s, if I remember correctly), using the passage from the elliptic curve to its associated Grossencharacter, and then from the Grossencharacter to the associated CM modular form. (This is a result in the opposite direction to the one you asked about, since it is about going from the Galois rep. to the modular forms; it seems worth mentioning though.) Another related comment: if you look in Shimura's book "Arithmetic theory of automorphic functions", he talks about abelian varieties attached to weight two eigenforms, but I think that the focus is more on the abelian varieties rather than the underlying system of $\ell$adic Galois representations. Summary: My overall take is that it took time for the idea of Galois representations attached to modular forms to evolve, with impetus from several different aspects of number theory and several different mathematicians. By the time Ribet wrote the article referred to in the comments, the whole picture was fairly clean, and he could make precise and straightforward statements about CM modular forms and the associated Galois reps. These were not new (in some sense)  they involve constructions and arguments going back to Hecke, Weil, Shimura, Taniyama, Serre, ...  but the language of Galois representations had only recently become available, and so Ribet may well have been the first to formulate them cleanly and generally in print. 

