@@ -89,21 +89,41 @@ module.exports = function process(path, option, callback) {
89
89
const { render, staticRenderFns } = compileTemplate ( content )
90
90
91
91
file . extname = '.js'
92
- file . contents = [
93
- `const styleInject = require('${ styleInjectFile } ')` ,
94
- `const styles = ${ styles ? JSON . stringify ( styles ) : null } ;` ,
95
- 'module.exports = {' ,
96
- ` render: ${ render } ,` ,
97
- ` components: ${ components } ,` ,
98
- ` staticRenderFns: ${ staticRenderFns } ,` ,
99
- ` mounted () {` ,
100
- ` this.cleanup = styles && styleInject(styles) ` ,
101
- ` },` ,
102
- ` destroyed () {` ,
103
- ` this.cleanup && this.cleanup()` ,
104
- ` }` ,
105
- '}'
106
- ] . join ( '\n' )
92
+
93
+ let epxortDelc = `module.exports = `
94
+ if ( option . moduleType === 'esm' ) {
95
+ epxortDelc = 'export default'
96
+ }
97
+
98
+ if ( option . extractCSS ) {
99
+ file . stylesheet = VFile ( {
100
+ path : file . path . replace ( / \. j s $ / , '.css' ) ,
101
+ contents : styles || ''
102
+ } )
103
+ file . contents = [
104
+ `${ epxortDelc } {` ,
105
+ ` render: ${ render } ,` ,
106
+ ` components: ${ components } ,` ,
107
+ ` staticRenderFns: ${ staticRenderFns } ,` ,
108
+ '}'
109
+ ] . join ( '\n' )
110
+ } else {
111
+ file . contents = [
112
+ `const styleInject = require('${ styleInjectFile } ')` ,
113
+ `const styles = ${ styles ? JSON . stringify ( styles ) : null } ;` ,
114
+ `${ epxortDelc } {` ,
115
+ ` render: ${ render } ,` ,
116
+ ` components: ${ components } ,` ,
117
+ ` staticRenderFns: ${ staticRenderFns } ,` ,
118
+ ` mounted () {` ,
119
+ ` this.cleanup = styles && styleInject(styles) ` ,
120
+ ` },` ,
121
+ ` destroyed () {` ,
122
+ ` this.cleanup && this.cleanup()` ,
123
+ ` }` ,
124
+ '}'
125
+ ] . join ( '\n' )
126
+ }
107
127
108
128
callback ( null , file )
109
129
}
0 commit comments