@@ -7,7 +7,8 @@ const compileTypescript = require('./compilers/typescript-compiler')
77const compileCoffeeScript = require ( './compilers/coffee-compiler' )
88const extractPropsFromFunctionalTemplate = require ( './extract-props' )
99const fs = require ( 'fs' )
10- const join = require ( 'path' ) . join
10+ const path = require ( 'path' )
11+ const join = path . join
1112const cssExtract = require ( 'extract-from-css' )
1213const logger = require ( './logger' )
1314const splitRE = / \r ? \n / g
@@ -28,13 +29,14 @@ function processScript (scriptPart) {
2829 return compileBabel ( scriptPart . content )
2930}
3031
31- function processStyle ( stylePart ) {
32+ function processStyle ( stylePart , filePath ) {
3233 if ( ! stylePart ) return { }
3334
3435 let cssCode = stylePart . content
3536 if ( / ^ s t y l | s t y l u s $ / . test ( stylePart . lang ) ) {
37+ const dir = path . dirname ( filePath )
3638 const stylus = require ( 'stylus' )
37- cssCode = stylus . render ( stylePart . content )
39+ cssCode = stylus . render ( stylePart . content , { paths : [ dir , process . cwd ( ) ] } )
3840 }
3941
4042 const cssNames = cssExtract . extractClasses ( cssCode )
@@ -57,13 +59,13 @@ function changePartsIfFunctional (parts) {
5759 }
5860}
5961
60- module . exports = function ( src , path ) {
62+ module . exports = function ( src , filePath ) {
6163 var parts = vueCompiler . parseComponent ( src , { pad : true } )
6264
6365 changePartsIfFunctional ( parts )
6466
6567 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' )
6769 }
6870
6971 const result = processScript ( parts . script )
@@ -75,7 +77,7 @@ module.exports = function (src, path) {
7577 scriptSrc = parts . script . content
7678 }
7779
78- const map = generateSourceMap ( script , '' , path , scriptSrc , inputMap )
80+ const map = generateSourceMap ( script , '' , filePath , scriptSrc , inputMap )
7981 let output = ';(function(){\n' + script + '\n})()\n' +
8082 'if (module.exports.__esModule) module.exports = module.exports.default\n' +
8183 'var __vue__options__ = (typeof module.exports === "function"' +
@@ -84,7 +86,7 @@ module.exports = function (src, path) {
8486
8587 if ( parts . template ) {
8688 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' )
8890 }
8991
9092 const renderFunctions = compileTemplate ( parts . template )
@@ -107,7 +109,7 @@ module.exports = function (src, path) {
107109 }
108110
109111 const moduleName = ast . module === true ? '$style' : ast . module
110- const styleObj = processStyle ( ast )
112+ const styleObj = processStyle ( ast , filePath )
111113
112114 return '\n this[\'' + moduleName + '\'] = ' + JSON . stringify ( styleObj )
113115 } ) . filter ( _ => _ )
0 commit comments