vuejs / component-compiler-utils

Lower level utilities for compiling Vue single file components
321 stars 75 forks source link

The `preprocessOptions` can not work when using `less` #24

Closed JaredCen closed 6 years ago

JaredCen commented 6 years ago
// styleProcessors/index.ts
const less = {
  render(
    source: string,
    map: any | null,
    options: any
  ): StylePreprocessorResults {
    const nodeLess = require('less')

    let result: any
    let error: Error | null = null
    nodeLess.render(
      source,
      { syncImport: true },
      (err: Error | null, output: any) => {
        error = err
        result = output
      }
    )

    if (error) return { code: '', errors: [error] }

    if (map) {
      return {
        code: result.css.toString(),
        map: merge(map, result.map),
        errors: []
      }
    }

    return { code: result.css.toString(), errors: [] }
  }
}

Here, this options is not used in nodeLess.render, when i want to assign the paths param in render function.

Justineo commented 6 years ago

@JunreyCen

F.Y.I., by specifying path in the options, less-loader will disable its built-in WebpackFileManager thus @imports inside Less files would stop using webpack's module-resolving algorithm.

znck commented 6 years ago

As far as I know,vue-loader is not using style preprocessor features of component-compiler-utils, it uses loader chain for preprocessing style blocks.

In other environment (rollup, jest, parcel), WebpackFileManager is not a thing so merging options should not pose any issues.

JaredCen commented 6 years ago

I use node/gulp to compile sfc instead of webpack since i don't want to bundle the dependence...btw, i need the commit published in npm, and thanks to fix this problem.