@@ -7,7 +7,8 @@ const compileTypescript = require('./compilers/typescript-compiler')
7
7
const compileCoffeeScript = require ( './compilers/coffee-compiler' )
8
8
const extractPropsFromFunctionalTemplate = require ( './extract-props' )
9
9
const fs = require ( 'fs' )
10
- const join = require ( 'path' ) . join
10
+ const path = require ( 'path' )
11
+ const join = path . join
11
12
const cssExtract = require ( 'extract-from-css' )
12
13
const logger = require ( './logger' )
13
14
const splitRE = / \r ? \n / g
@@ -28,13 +29,14 @@ function processScript (scriptPart) {
28
29
return compileBabel ( scriptPart . content )
29
30
}
30
31
31
- function processStyle ( stylePart ) {
32
+ function processStyle ( stylePart , filePath ) {
32
33
if ( ! stylePart ) return { }
33
34
34
35
let cssCode = stylePart . content
35
36
if ( / ^ s t y l | s t y l u s $ / . test ( stylePart . lang ) ) {
37
+ const dir = path . dirname ( filePath )
36
38
const stylus = require ( 'stylus' )
37
- cssCode = stylus . render ( stylePart . content )
39
+ cssCode = stylus . render ( stylePart . content , { paths : [ dir , process . cwd ( ) ] } )
38
40
}
39
41
40
42
const cssNames = cssExtract . extractClasses ( cssCode )
@@ -57,13 +59,13 @@ function changePartsIfFunctional (parts) {
57
59
}
58
60
}
59
61
60
- module . exports = function ( src , path ) {
62
+ module . exports = function ( src , filePath ) {
61
63
var parts = vueCompiler . parseComponent ( src , { pad : true } )
62
64
63
65
changePartsIfFunctional ( parts )
64
66
65
67
if ( parts . script && parts . script . src ) {
66
- parts . script . content = fs . readFileSync ( join ( path , '..' , parts . script . src ) , 'utf8' )
68
+ parts . script . content = fs . readFileSync ( join ( filePath , '..' , parts . script . src ) , 'utf8' )
67
69
}
68
70
69
71
const result = processScript ( parts . script )
@@ -75,7 +77,7 @@ module.exports = function (src, path) {
75
77
scriptSrc = parts . script . content
76
78
}
77
79
78
- const map = generateSourceMap ( script , '' , path , scriptSrc , inputMap )
80
+ const map = generateSourceMap ( script , '' , filePath , scriptSrc , inputMap )
79
81
let output = ';(function(){\n' + script + '\n})()\n' +
80
82
'if (module.exports.__esModule) module.exports = module.exports.default\n' +
81
83
'var __vue__options__ = (typeof module.exports === "function"' +
@@ -84,7 +86,7 @@ module.exports = function (src, path) {
84
86
85
87
if ( parts . template ) {
86
88
if ( parts . template . src ) {
87
- parts . template . content = fs . readFileSync ( join ( path , '..' , parts . template . src ) , 'utf8' )
89
+ parts . template . content = fs . readFileSync ( join ( filePath , '..' , parts . template . src ) , 'utf8' )
88
90
}
89
91
90
92
const renderFunctions = compileTemplate ( parts . template )
@@ -107,7 +109,7 @@ module.exports = function (src, path) {
107
109
}
108
110
109
111
const moduleName = ast . module === true ? '$style' : ast . module
110
- const styleObj = processStyle ( ast )
112
+ const styleObj = processStyle ( ast , filePath )
111
113
112
114
return '\n this[\'' + moduleName + '\'] = ' + JSON . stringify ( styleObj )
113
115
} ) . filter ( _ => _ )
0 commit comments