1
1
const fs = require ( 'fs' )
2
- const path = require ( 'path' ) . posix
3
2
const execSync = require ( 'child_process' ) . execSync
3
+ const path = require ( 'path' ) [ process . platform === 'win32' ? 'win32' : 'posix' ]
4
4
5
5
const VUE_WRAPPER = process . env . IS_DEV ? 'src/vue-wrapper.js' : 'lib/vue-wrapper.js'
6
6
const REACT_WRAPPER = process . env . IS_DEV ? 'src/react-wrapper.jsx' : 'lib/react-wrapper.js'
7
7
8
+ const pathCrossEnv = ( path ) =>
9
+ process . platform !== 'win32' ? path : path . replace ( / \\ / g, '/' )
10
+
8
11
module . exports = function bundle ( Components , out , config ) {
9
12
if ( ! Components . length ) {
10
13
return
@@ -27,11 +30,15 @@ module.exports = function bundle (Components, out, config) {
27
30
`
28
31
}
29
32
if ( reactComponents . length ) {
33
+ const reactWrapperRelPath = pathCrossEnv (
34
+ path . relative ( absoluteOut , path . join ( __dirname , REACT_WRAPPER ) )
35
+ )
36
+
30
37
init = init + `
31
38
import React from "react";\n
32
39
import ReactDOM from "react-dom";\n
33
40
34
- import ReactWrapper from '${ path . relative ( absoluteOut , path . join ( __dirname , REACT_WRAPPER ) ) } ';\n
41
+ import ReactWrapper from '${ reactWrapperRelPath } ';\n
35
42
window.React = React;\n
36
43
window.ReactDOM = ReactDOM;\n
37
44
window.ReactWrapper = ReactWrapper;\n
@@ -47,8 +54,9 @@ module.exports = function bundle (Components, out, config) {
47
54
if ( config . betterDocs . component ) {
48
55
if ( config . betterDocs . component . wrapper ) {
49
56
const absolute = path . resolve ( config . betterDocs . component . wrapper )
57
+ const relative = pathCrossEnv ( path . relative ( absoluteOut , absolute ) )
50
58
init += `
51
- import _CustomWrapper from '${ path . relative ( absoluteOut , absolute ) } ';\n
59
+ import _CustomWrapper from '${ relative } ';\n
52
60
window._CustomWrapper = _CustomWrapper;\n
53
61
`
54
62
}
@@ -57,10 +65,10 @@ module.exports = function bundle (Components, out, config) {
57
65
init = `${ config . betterDocs . component . entry . join ( '\n' ) } \n${ init } `
58
66
}
59
67
}
60
-
68
+
61
69
const entryFile = init + Components . map ( ( c , i ) => {
62
70
const { displayName, filePath, type } = c . component
63
- const relativePath = path . relative ( absoluteOut , filePath )
71
+ const relativePath = pathCrossEnv ( path . relative ( absoluteOut , filePath ) )
64
72
const name = `Component${ i } `
65
73
return [
66
74
`import ${ name } from '${ relativePath } ';` ,
@@ -82,4 +90,4 @@ module.exports = function bundle (Components, out, config) {
82
90
}
83
91
throw error
84
92
}
85
- }
93
+ }
0 commit comments