-
Notifications
You must be signed in to change notification settings - Fork 72
Migration 0.1.x 1.0.x
The upgrade to version 1.0.x
involves some changes to the way that the less middleware works.
Unfortunately this includes some changes that need to be made to the way you use the middleware.
This is the first and most important change that all users of the middleware will need to update.
Previously the source directory was specified in the options
argument of the middleware like so:
lessMiddleware({
src: path.join(__dirname, '/public')
})
Since the source directory is really a required argument this was a bit of a misnomer.
So starting in version 1.0.x
the first argument to the middleware is the source directory and is required:
lessMiddleware(path.join(__dirname, '/public'))
One of the big pain points with the earlier version of the middleware was the inability to pass options directly to the less parser and compiler. To fix this there are now three different option objects that get passed into the middleware:
lessMiddleware(source, [{options}], [{parserOptions}], [{compilerOptions}])
The options
objects contains options that are specific to the middleware and have no bearing on the less parser or compiler.
The parserOptions
and compilerOptions
do not affect the middleware but are passed into the Less parser and compiler directly.
More information on the option objects can be found in the readme.
The following options have been changed from earlier versions:
-
compress
: Removed fromoptions
. Can be specified in thecompilerOptions
. -
dumpLineNumbers
: Removed fromoptions
. Can be specified in theparserOptions
. -
optimization
: Removed fromoptions
. Can be specified in theparserOptions
. -
paths
: Removed fromoptions
. Can be specified in theparserOptions
. -
preprocessor
: Moved to be available atpreprocessor.less
. -
relativeUrls
: Removed fromoptions
. Can be specified in theparserOptions
. -
sourceMap
: Removed fromoptions
. Can be specified in thecompilerOptions
. -
yuicompress
: Removed fromoptions
. Can be specified in thecompilerOptions
.
While reorganizing, some options have been removed:
-
prefix
: Removed in favor of using thepreprocess.path
option. -
treeFunctions
: Removed, see the extending less page for how to add custom tree functions.
To make thing easier to extend, a few new options have been added: preprocessing and postprocessing. Specific examples are available on the wiki, but in the following are available:
-
postprocess.css
: Modifies the compiled css output before being stored. -
preprocess.less
: Modifies the raw less before being parsed and compiled. -
preprocess.path
: Modifies the less pathname before being loaded from the filesystem.
Instead of using a prefix
option you now need to use the preprocess.path
option:
preprocess: {
path: function(pathname, req) {
return pathname.replace(/^\/styles\//, '/');
}
}