Where does the expression “Pipe Dream” come from and What does Pipe Dream mean?

A dream full of illusions such as results from the smoking of an opium pipe, which was the source of the term “Pipe Dream”.

As American slang heard just about at the beginning of the present century, and apparently first appeared in print in Wallace Irwin’s Love Sonnets of a Hoodlum (1901):

To just one girl I’ve tuned my sad bazoo,
Stringing my pipe-dream off as it occurred.