Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
dynamic require from the cjs dist of less
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 22, 2020
1 parent 99ed498 commit b80d80b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/less-cache.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ class LessCache

observeImportedFilePaths: (callback) ->
importedPaths = []
lessFs ?= require 'less/lib/less-node/fs.js'
# load or assign less and lessFs
if (less == null)
less = require 'less'
lessFs = less.fs
else if (lessFs == null)
lessFs = less.fs
originalFsReadFileSync = lessFs.readFileSync
lessFs.readFileSync = (filePath, args...) =>
relativeFilePath = @relativize(@resourcePath, filePath) if @resourcePath
Expand Down Expand Up @@ -196,7 +201,12 @@ class LessCache
parseLess: (filePath, contents) ->
css = null
options = filename: filePath, syncImport: true, paths: @importPaths
less ?= require('less')
# load or assign less and lessFs
if (less == null)
less = require 'less'
lessFs = less.fs
else if (lessFs == null)
lessFs = less.fs
imports = @observeImportedFilePaths ->
less.render contents, options, (error, result) ->
if error?
Expand Down

0 comments on commit b80d80b

Please sign in to comment.