1+ 'use strict' ;
2+
3+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
4+
5+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
6+
7+ var _pretty = require ( 'pretty' ) ;
8+
9+ var _pretty2 = _interopRequireDefault ( _pretty ) ;
10+
11+ var _requirefresh = require ( 'requirefresh' ) ;
12+
13+ var _requirefresh2 = _interopRequireDefault ( _requirefresh ) ;
14+
15+ var _errors = require ( './utils/errors' ) ;
16+
17+ var _errors2 = _interopRequireDefault ( _errors ) ;
18+
19+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
20+
21+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
22+
23+ require ( 'babel-register' ) ( {
24+ extensions : [ '.js' , '.jsx' ]
25+ } ) ;
26+
27+ var StaticRenderHtmlWebpackPlugin = function ( ) {
28+ function StaticRenderHtmlWebpackPlugin ( options ) {
29+ _classCallCheck ( this , StaticRenderHtmlWebpackPlugin ) ;
30+
31+ this . options = Object . assign ( { } , {
32+ entry : '' ,
33+ pretty : false
34+ } , options ) ;
35+ }
36+
37+ _createClass ( StaticRenderHtmlWebpackPlugin , [ {
38+ key : 'apply' ,
39+ value : function apply ( compiler ) {
40+ var _this = this ;
41+
42+ var entry = this . options . entry ;
43+
44+ compiler . plugin ( 'emit' , function ( compilation , callback ) {
45+ var result = '' ;
46+
47+ if ( ! entry ) {
48+ compilation . errors . push ( _errors2 . default . emptyEntry ( compiler . context ) ) ;
49+ return callback ( ) ;
50+ }
51+
52+ var FILE_SUPPORT_REGEXP = / .( j s | j s x ) $ / g;
53+ var fileExtension = entry . split ( '.' ) ;
54+ fileExtension = '.' + fileExtension [ fileExtension . length - 1 ] ;
55+
56+ if ( ! FILE_SUPPORT_REGEXP . test ( fileExtension ) ) {
57+ compilation . errors . push ( _errors2 . default . fileExtension ( entry , compiler . context ) ) ;
58+ return callback ( ) ;
59+ }
60+
61+ try {
62+ result = ( 0 , _requirefresh2 . default ) ( entry ) ;
63+ } catch ( error ) {
64+ compilation . errors . push ( _errors2 . default . errorWrapper ( error ) ) ;
65+ return callback ( ) ;
66+ }
67+
68+ compilation . fileDependencies . push ( entry ) ;
69+
70+ if ( result . default && _typeof ( result . default ) === 'object' ) {
71+ result = result . default ;
72+ }
73+
74+ Object . keys ( result ) . map ( function ( key ) {
75+ var file = {
76+ name : key + '.html' ,
77+ source : result [ key ] ,
78+ size : result [ key ] . length
79+ } ;
80+
81+ var html = file . source ;
82+
83+ if ( _this . options . pretty ) {
84+ try {
85+ html = ( 0 , _pretty2 . default ) ( html ) ;
86+ } catch ( error ) {
87+ html = 'Error: \'' + error + '\'\nFile: \'' + entry + '\'\nProperty: \'' + key + '\'' ;
88+ compilation . errors . push ( _errors2 . default . errorWrapper ( error ) ) ;
89+ }
90+ }
91+
92+ compilation . assets [ file . name ] = {
93+ source : function source ( ) {
94+ return html ;
95+ } ,
96+ size : function size ( ) {
97+ return file . size ;
98+ }
99+ } ;
100+ } ) ;
101+ callback ( ) ;
102+ } ) ;
103+ }
104+ } ] ) ;
105+
106+ return StaticRenderHtmlWebpackPlugin ;
107+ } ( ) ;
108+
109+ module . exports = StaticRenderHtmlWebpackPlugin ;
0 commit comments