File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ /node_modules /
2
+ /dist /
3
+ npm-debug.log
Original file line number Diff line number Diff line change
1
+ var fs = require ( 'fs' )
2
+
3
+ var inlineReg = / < ! - - i n l i n e - p l u g i n [ \w \W \r \n ] * ?- - > / g
4
+ var pathReg = / p a t h = " ( .* ?) " /
5
+
6
+ function wrapScript ( script ) {
7
+ return '<script>' + script + '</script>\n'
8
+ }
9
+
10
+ function HtmlWebpackInlinePlugin ( options ) {
11
+ // Setup the plugin instance with options...
12
+ this . options = options
13
+ }
14
+
15
+ HtmlWebpackInlinePlugin . prototype . apply = function ( compiler ) {
16
+ compiler . plugin ( 'compilation' , function ( compilation , options ) {
17
+ compilation . plugin ( 'html-webpack-plugin-before-html-processing' , function ( htmlPluginData , callback ) {
18
+ var html = htmlPluginData . html
19
+ var tags = html . match ( inlineReg )
20
+ if ( tags ) {
21
+ tags . forEach ( function ( tag ) {
22
+ var ret = tag . match ( pathReg )
23
+ if ( ret && ret [ 1 ] ) {
24
+ var scriptContent = fs . readFileSync ( ret [ 1 ] , 'utf8' )
25
+ html = html . replace ( tag , wrapScript ( scriptContent ) )
26
+ }
27
+ } )
28
+ htmlPluginData . html = html
29
+ }
30
+ callback ( null , htmlPluginData )
31
+ } ) ;
32
+ } ) ;
33
+ } ;
34
+
35
+ module . exports = HtmlWebpackInlinePlugin
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " html-webpack-inline-plugin" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " " ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "author" : " " ,
10
+ "license" : " MIT"
11
+ }
You can’t perform that action at this time.
0 commit comments