It was hard, but we finally did the job (!). Arggh - so much time was spent trying to figure out the syntax.
Here's the problem: during the build, we want to determine the path that should be used as the base url for different resources in fewer files (background images using the url () less function).
First, we defined the path in the webpack configuration file. Its simple JS, but the escape pattern for the path string was absolutely nutty. We probably invested hours just for that. Awesome . Here he is:
var assetsPath = (someCondition) ? '/assets' : "\\/127.0.0.1:8080/assets";
The following is the bootloader configuration for fewer files using the assetsPath prefix above:
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css?minimize=false!less?{"modifyVars":{"assetspath":"\'' + assetsPath +'\'"}}' }
Pay attention to the screening pattern above, where the assetsPath property is used in the bootloader configuration.
Then you need to make sure that an empty variable is defined in fewer files. We initialized it in our 'vars.less' file using:
@assetspath: '';
Finally, in any appropriate class, we can use the value passed during assembly, for example:
background-image: url("@{assetspath}/images/facebook.png");
source share