We have applied the extended factorization scheme to investigate the electroweak pion production on nuclei. The ANL-Osaka model, which was obtained by analyzing the data of $\pi N$, $\gamma N$, $N(e,e'\pi)$ and $N(\nu,\mu\,\pi) $ reactions up to invariant mass $W=$ 2 GeV, is used to generate the matrix elements of current operators relevant to pion-production off the nucleon. Medium effects on the $\Delta$ (1232) component of meson-exchange current are included by using a $\Delta$-nucleus potential determined from the previous $\Delta$-hole model studies of pion-nucleus reactions. Nuclear correlations in the initial target state and in the spectator system(s) are modeled using realistic hole spectral functions. As a first step, we show that the data of $^{12}$C$(e,e')$ up to the $\Delta$ (1232) region can be described reasonably well. The interplay between the pion production and two-body meson-exchange mechanisms is shown to be essential in improving the agreement with the data in the ``dip'' region, between the quasielastic and the $\Delta$ (1232) peaks. Predictions for $^{12}$C$(\nu,\mu\,\pi)$ have also been made. They can be used to estimate pion-emission rates in neutrino-nucleus cross section, which constitutes an important systematic uncertainty to the reconstructed neutrino energy. With further improvements of the Metropolis Monte-Carlo techniques to account for final states comprised of more than two particles, our approach can be employed up to $W=$ 2 GeV, where two-pion production and higher mass nucleon resonances must be included for analyzing the data from accelerator-based neutrino-oscillation experiments.