lcxfs1991 / html-res-webpack-plugin

plugin for generating html in webpack
167 stars 34 forks source link

想写个插件在生成js的最前面 插入一段js代码 js代码window.pad = pad pad是传进来的 #22

Closed wood-liu92 closed 7 years ago

wood-liu92 commented 7 years ago

应该怎么在什么时候插入呢? 怎么获取到webpack编译的代码呢?

lcxfs1991 commented 7 years ago

可以使用,或者参考这个项目: https://github.com/lcxfs1991/banner-webpack-plugin @lww555

wood-liu92 commented 7 years ago

15f57187-8993-416e-a0ab-20efd5e3369d

代码已经插入进去了 但是总是报 as2 is not a function 这是怎么回事呢

lcxfs1991 commented 7 years ago

你有在代码里,调用 window.pad() ?

wood-liu92 commented 7 years ago

image 我在代码里没有调用 window.pad() 。

lcxfs1991 commented 7 years ago

你多加个分号呢?

wood-liu92 commented 7 years ago

可以了,果然是分号的事。谢谢大神

wood-liu92 commented 7 years ago

最近想写webpack插件 但是看compiler, compilation的源码 完全看不懂啊。需要哪些基础知识呢. 是看 他提供的Plugin API吗?

lcxfs1991 commented 7 years ago

老早的时候写的,有一定参考价值 https://github.com/lcxfs1991/blog/issues/1 另外这里也有一些文章参考: https://github.com/webpack-china/awesome-webpack-cn