Giter VIP home page Giter VIP logo

component-compiler-utils's Introduction

@vue/component-compiler-utils Build Status

Lower level utilities for compiling Vue single file components

This package contains lower level utilities that you can use if you are writing a plugin / transform for a bundler or module system that compiles Vue single file components into JavaScript. It is used in vue-loader version 15 and above.

The API surface is intentionally minimal - the goal is to reuse as much as possible while being as flexible as possible.

Why isn't vue-template-compiler a peerDependency?

Since this package is more often used as a low-level utility, it is usually a transitive dependency in an actual Vue project. It is therefore the responsibility of the higher-level package (e.g. vue-loader) to inject vue-template-compiler via options when calling the parse and compileTemplate methods.

Not listing it as a peer depedency also allows tooling authors to use a non-default template compiler instead of vue-template-compiler without having to include it just to fullfil the peer dep requirement.

API

parse(ParseOptions): SFCDescriptor

Parse raw single file component source into a descriptor with source maps. The actual compiler (vue-template-compiler) must be passed in via the compiler option so that the specific version used can be determined by the end user.

interface ParseOptions {
  source: string
  filename?: string
  compiler: VueTemplateCompiler
  // https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler#compilerparsecomponentfile-options
  // default: { pad: 'line' }
  compilerParseOptions?: VueTemplateCompilerParseOptions
  sourceRoot?: string
  needMap?: boolean
}

interface SFCDescriptor {
  template: SFCBlock | null
  script: SFCBlock | null
  styles: SFCBlock[]
  customBlocks: SFCCustomBlock[]
}

interface SFCCustomBlock {
  type: string
  content: string
  attrs: { [key: string]: string | true }
  start: number
  end: number
  map?: RawSourceMap
}

interface SFCBlock extends SFCCustomBlock {
  lang?: string
  src?: string
  scoped?: boolean
  module?: string | boolean
}

compileTemplate(TemplateCompileOptions): TemplateCompileResults

Takes raw template source and compile it into JavaScript code. The actual compiler (vue-template-compiler) must be passed in via the compiler option so that the specific version used can be determined by the end user.

It can also optionally perform pre-processing for any templating engine supported by consolidate.

interface TemplateCompileOptions {
  source: string
  filename: string

  compiler: VueTemplateCompiler
  // https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler#compilercompiletemplate-options
  // default: {}
  compilerOptions?: VueTemplateCompilerOptions

  // Template preprocessor
  preprocessLang?: string
  preprocessOptions?: any

  // Transform asset urls found in the template into `require()` calls
  // This is off by default. If set to true, the default value is
  // {
  //   audio: 'src',
  //   video: ['src', 'poster'],
  //   source: 'src',
  //   img: 'src',
  //   image: ['xlink:href', 'href'],
  //   use: ['xlink:href', 'href']
  // }
  transformAssetUrls?: AssetURLOptions | boolean

  // For vue-template-es2015-compiler, which is a fork of Buble
  transpileOptions?: any

  isProduction?: boolean  // default: false
  isFunctional?: boolean  // default: false
  optimizeSSR?: boolean   // default: false

  // Whether prettify compiled render function or not (development only)
  // default: true
  prettify?: boolean
}

interface TemplateCompileResult {
  ast: Object | undefined
  code: string
  source: string
  tips: string[]
  errors: string[]
}

interface AssetURLOptions {
  [name: string]: string | string[]
}

Handling the Output

The resulting JavaScript code will look like this:

var render = function (h) { /* ... */}
var staticRenderFns = [function (h) { /* ... */}, function (h) { /* ... */}]

It does NOT assume any module system. It is your responsibility to handle the exports, if needed.

compileStyle(StyleCompileOptions)

Take input raw CSS and applies scoped CSS transform. It does NOT handle pre-processors. If the component doesn't use scoped CSS then this step can be skipped.

interface StyleCompileOptions {
  source: string
  filename: string
  id: string
  map?: any
  scoped?: boolean
  trim?: boolean
  preprocessLang?: string
  preprocessOptions?: any
  postcssOptions?: any
  postcssPlugins?: any[]
}

interface StyleCompileResults {
  code: string
  map: any | void
  rawResult: LazyResult | void // raw lazy result from PostCSS
  errors: string[]
}

compileStyleAsync(StyleCompileOptions)

Same as compileStyle(StyleCompileOptions) but it returns a Promise resolving to StyleCompileResults. It can be used with async postcss plugins.

component-compiler-utils's People

Contributors

3cp avatar akryum avatar boxizen avatar brianhelba avatar dependabot[bot] avatar ishitatsuyuki avatar jinjiang avatar joma74 avatar jounqin avatar kazupon avatar lenkog avatar meteorlxy avatar mikemenaker avatar mliew21396 avatar ne-smalltown avatar pikax avatar pwang2 avatar qc-l avatar shockingsrose avatar sodatea avatar ulivz avatar underfin avatar ypresto avatar yyx990803 avatar znck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

component-compiler-utils's Issues

Allow both node-sass and sass

We have issue with vue-jest, that uses this package. (vuejs/vue-jest#137 (comment)).
It would be nice to borrow experience on sass-loader and provide a choice of what to use: node-sass or sass (https://github.com/webpack-contrib/sass-loader/blob/master/src/getDefaultSassImplementation.js)

sass-loader requires you to install either Node Sass or Dart Sass on your own (more documentation can be found below). This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.

typescript definition for SFCDescriptor isn't compatible with vue-template-compiler

SFCDescriptor in component-compiler-utils:
screenshot_2020-05-18_11-37-30

SFCDescriptor in vue-template-compiler:
screenshot_2020-05-18_11-37-30

result:

Type 'typeof import("c:/code/vscode-fe-helper/node_modules/vue-template-compiler/types/index")' is not assignable to type 'VueTemplateCompiler'.
  The types of 'parseComponent(...).template' are incompatible between these types.
    Type 'SFCBlock | undefined' is not assignable to type 'SFCBlock | null'.
      Type 'undefined' is not assignable to type 'SFCBlock | null'

screenshot_2020-05-18_11-37-30

Vue loader breaks with version 3.0.1

version v3.0.1 is missing the lib folder, which causes:

node_modules/vue-loader/lib/index.d.ts:2:37 - error TS2307: Cannot find module '@vue/component-compiler-utils/lib/types'.

2 import { VueTemplateCompiler } from '@vue/component-compiler-utils/lib/types'

Please remove prettier

A compiler shouldn't depend on code formatting / beautifier utilities. That's the job of the IDE. vscode already handles this very well, for example.

Would you please remove prettier dependency?

Dependency on vue-template-compiler

The component-compiler-utils module requires vue-template-compiler, but it's not listed as a dependency (only a dev dependency). When I use vue-loader with a custom template compiler, and I don't install vue-template-compiler, I get an error.

Of course as a workaround I can install vue-template-compiler manually. But in that case I end up having three template compilers installed: vue-template-compiler, vue-template-es2015-compiler and my custom template compiler. Is that intentional?

VueJS not rendering component on jquery ajax load

I have html via AJAX call which contain components. my problem is component-a is not rending, is it possible in jquery ajax load? i tried vm.compile() and vm.$forceUpdate() on .load callback but nothing happens.

Set Pug's doctype option to html by default

Pug's doctype option is set to html by default in pug-plain-loader.
The reasoning is also explained there:

The doctype option is set to html by default, since most Vue templates are HTML fragments without explicit doctype.

The same we should do here in component-compiler-utils (otherwise developers should figure it out and set it by themesevles vuejs/vue-jest#170)

I can create a PR if we agree to do it

Test suite failing on CI

#!/bin/bash -eo pipefail
yarn test
yarn run v1.6.0
$ prettier --list-different "{lib,test}/**/*.ts" && jest --coverage
 FAIL  test/compileStyle.spec.ts
  โ— Test suite failed to run

    SecurityError: localStorage is not available for opaque origins
      
      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
      at Array.forEach (native)

 FAIL  test/stylePluginScoped.spec.ts
  โ— Test suite failed to run

    SecurityError: localStorage is not available for opaque origins
      
      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
      at Array.forEach (native)

 FAIL  test/compileTemplate.spec.ts
  โ— Test suite failed to run

    SecurityError: localStorage is not available for opaque origins
      
      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
      at Array.forEach (native)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 3 failed, 3 total
Tests:       0 total
Snapshots:   0 total
Time:        1.225s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code 1

https://www.npmjs.com/advisories/1693


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ moderate      โ”‚ Regular Expression Denial of Service                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ postcss                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=8.2.10                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ vue-loader                                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ vue-loader > @vue/component-compiler-utils > postcss         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://www.npmjs.com/advisories/1693                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ moderate      โ”‚ Regular Expression Denial of Service                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ postcss                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=8.2.10                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ nuxt                                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ nuxt > @nuxt/builder > @nuxt/webpack > vue-loader >          โ”‚
โ”‚               โ”‚ @vue/component-compiler-utils > postcss                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://www.npmjs.com/advisories/1693                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ moderate      โ”‚ Regular Expression Denial of Service                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ postcss                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=8.2.10                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ nuxt                                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ nuxt > @nuxt/webpack > vue-loader >                          โ”‚
โ”‚               โ”‚ @vue/component-compiler-utils > postcss                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://www.npmjs.com/advisories/1693                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ moderate      โ”‚ Regular Expression Denial of Service                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ postcss                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=8.2.10                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ vue-jest                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ vue-jest > @vue/component-compiler-utils > postcss           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://www.npmjs.com/advisories/1693                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


prettier remove default parser breaks the tool

In prettier 1.13.0, default parser was removed with a minor version(used to be babylon), this breaks the formatter here.

code = prettier.format(code, { semi: false })

Issue has been created in prettier repo as well, attached here for tracking purpose.
prettier/prettier#4567

Adding error stack info below for our friend Google to route new comers to:

ERROR in ./src/client/components/Com1.vue?vue&type=template&id=22d07c36 (../happy-cli/node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../happy-cli/node_modules/vue-loader/lib??vue-loader-options!./src/client/components/Com1.vue?vue&type=template&id=22d07c36)

Module build failed: Error: No parser and no file path given, couldn't infer a parser.
    at normalize ({project_dir}/node_modules/prettier/index.js:7051:13)
    at formatWithCursor ({project_dir}/node_modules/prettier/index.js:10370:12)
    at {project_dir}/node_modules/prettier/index.js:31115:15
    at Object.format ({project_dir}/node_modules/prettier/index.js:31134:12)
    at actuallyCompile ({project_dir}/node_modules/@vue/component-compiler-utils/dist/compileTemplate.js:93:29)
    at compileTemplate ({project_dir}/node_modules/@vue/component-compiler-utils/dist/compileTemplate.js:26:16)
    at Object.module.exports ({project_dir}/node_modules/vue-loader/lib/loaders/templateLoader.js:42:20)

PR: #15

Reason for pinning prettier to specific version, 1.16.3?

In our build we have noticed an inconsistency with dependencies. Namely, we noticed that yarn is pulling in two versions of prettier. Upon investigation, it was because this package asks for a specific version of prettier (while our app asks for another). Other Vue packages (for example, @vue/eslint-config-prettier) require minor versions---^1.16.3

Is this possibly a bug? Should it be ^1.16.3 as well? Or is there a reason for this specific version of prettier?

feature request: supporting custom urlToRequire function

Allow transformAssetUrls to be used like this:

transformAssetUrls: {
  'optimize-img': {
     src: value => `require('!optimize-img-loader!${value}')`
  }
}
<template>
  <optimize-img src="./foo.png" />
</template>

I can create a PR if you think it's useful.

TypeError: Class constructor LRUCache cannot be invoked without 'new'

With LRUCache updated to version 5.1.1, the vue component compiler utils throw the error
TypeError: Class constructor LRUCache cannot be invoked without 'new'

I think this is due to line 9 in lib/parse.ts:

const cache = require('lru-cache')(100)`;

If this would be changed to

const LRUCache = require('lru-cache');
const cache = LRUCache(100);

I think this would fix the problem.

Does it make sense?

:root Selector should not be scoped

The :root CSS pseudo-class matches the root element of a tree representing the document, it identical to the selector html usually.

But a scoped :root selector dose not match any Element.

With a demonstration which created by @vue/cli 4.0.5๏ผš

<!--HelloWorld.vue-->
<style scoped>
:root {
  --font-color: red;
}
h3 {
  color: var(--font-color);
}
</style>

And we got:

<style type="text/css">
[data-v-469af010]:root {
  --font-color: red;
}
h3[data-v-469af010] {
  color: var(--font-color);
}
</style>

h3's font-color wont change, it still inherits from parent element rather than red.

How to resolve?

Scoped :root does not match any element, but a attribute selector with :root do. So, we can get the expected result if changing:

[data-v-469af010]:root { /*balabala*/ }

to

/* proposal A: */
:root { /*balabala*/ }

/* or  */

/* proposal B: */
:root [data-v-469af010] { /*balabala*/ }

I prefer proposal B that will make sure the scoped style rendered as wished. Such as:

<!-- HelloWorld.vue -->
<template>
  <h3>Hello</h3>
</template>

<style scoped>
:root {
  --font-color: red;
}
h3 {
  color: var(--font-color);
}
</style>

<!-- another unscoped style in HelloWorld.vue-->
<style>
:root {
  --font-color: blue;
}
</style>

We will get some css code like this:

<style type="text/css">
:root [data-v-469af010] {
  --font-color: red;
}
h3[data-v-469af010] {
  color: var(--font-color);
}
</style>
<style type="text/css">
:root {
  --font-color: blue;
}
</style>

h3 will rendered with red font color as expected.

I'll create a PR if this issue is logical.

TypeError: postcss_1.default is not a function

Summary

Version: 1.2.0

Recently many users reported an error at vuejs/vuepress#268, and I reproduced it at my local.

After the investigation, I found:

result = postcss(plugins).process(source, postCSSOptions)

It's will be compiled into:

result = postcss_1.default(plugins).process(source, postCSSOptions);

But in postcss's dist code, the module was exported as:

exports.default = postcss;
module.exports = exports['default'];

So the module should be used as postcss_1 instead of postcss_1.default.

And I don't know if this is a problem of TSC. but it's truly a issue introduced by upgrade of vue-loader/@vuejs/component-compiler-utils

Invalid source map generated by parse

return map.toJSON()

{ version: 3,
  sources:
   [ '/Users/znck/Workspace/Experiments/repro-rollup-plugin-vue/src/App.vue' ],
  names: [],
  mappings:
   [ [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [ Int32Array [ 0, 0, 11, 0 ] ],
     [ Int32Array [ 0, 0, 12, 0 ] ],
     [ Int32Array [ 0, 0, 13, 0 ] ] ],
  file:
   '/Users/znck/Workspace/Experiments/repro-rollup-plugin-vue/src/App.vue',
  sourceRoot: '/Users/znck/Workspace/Experiments/repro-rollup-plugin-vue',
  sourcesContent:
   [ '<script>\nexport default {\n  \n}\n</script>\n\n<template>\n  <div class="foo">foo</div>\n</template>\n\n<style>\n.foo { \n  color: red;\n}\n</style>' ] }

mappings should be string.

Related: vuejs/rollup-plugin-vue#251

compiler undefined in parse.ts

compiler undefined in parse.ts. when I want to compile single vue component as normal.
[ Can't read parseComponent of undefined... ]

TypeError: Super Expression must either be null or a function

I made this same issue on the require-extension-hooks-vue repo. Since I don't know quite where this falls under.

It seems like maybe prettier but I am unsure since it may also be related to Vue?

I am using the hooks repo to setup and run unit tests, however I keep getting this same type error of Super Expression must either be null or a function

I'm not sure why this started happening. You can reproduce it if you simply clone the require-extension-hooks-vue repo here: https://github.com/jackmellis/require-extension-hooks-vue

Any pointers or a possible work around would be greatly appreciated! Maybe I'm just being dumb even I dunno.

Provide installation instructions on missing language preprocessors

If a template is using pug syntax and pug package is not installed, it fails. There should be graceful warning explaining what failed and how to resolve it.

For example:

Component Example.vue uses lang pug for template. Please install the language preprocessor.

$ npm add -D pug

Source-map issue on windows

First, mozilla/source-map doesn't support \ as separator at all, because it's designed to be consumed in browser.

mozilla/source-map#91

  1. the file and sourceRoot has to be normalized.
    const map = new SourceMapGenerator({
    file: filename,
    sourceRoot
{
  file: filename.replace(/\\/g, '/'),
  sourceRoot: sourceRoot.replace(/\\/g, '/')
}

There is one more to be fixed in @vue/component-compiler.
https://github.com/vuejs/vue-component-compiler/blob/afa1cd440123e2e0c195908c1e15935273ac64a9/src/assembler.ts#L77

  1. actually the default sourceRoot doesn't make much sense, because when serving the source-map to browser, process.cwd() is irrelevant.
    sourceRoot = process.cwd(),

Change to

sourceRoot = '',

With the above two fixes, it can fix https://travis-ci.org/dumberjs/gulp-vue-file/builds/477568946
Update: I managed to fix the gulp-vue-file bug within gulp-vue-file by rewriting sourcemaps (normalize sources and file path). But the incoming sourcemaps should also be fixed in vue compiler.

Let me know what you think, I can make some PRs for this.

Contact on how to use this

Trying to use @vue/component-compiler-utils but I can't figure it out. So if you can point me to a contact or a forum or a wiki, that would be great. Thanks in advance.

Typo on README

I was searching in my own codebase and forgot to exclude the node_modules folder on that search. With that I found two typos in your README file... ยฏ\(ใƒ„)/ยฏ

On Why isn't vue-template-compiler a peerDependency?, you have:

"Not listing it as a peer depedency also allows"

and

"it just to fullfil the peer"

Support dart-sass

Support for node-sass seems to be hardcoded into this plugin via @vue/component-compiler-utils. It would be great if node-sass could be switched out with dart-sass.

Maybe this is already possible and I'm just overlooking an option?

Sass imports not working from node_modules

Expected behavior

I'm using SFC (single file component) hybrid where my js and sass file are linked from my vue file. The sass file itself imports files located in installed packages in node_modules/. With webpack vue plugin these easily get resolved by prefix an npm sass dependency with ~

Actual behavior

I just get these errors regardless of the file I am trying to load from node modules (example package named mymodule with file.scss sitting in root of it):

(VuePlugin plugin) Error: Error: File to import not found or unreadable: ~mymodule/file.scss.

Steps to reproduce the behavior

Create an SFC file and change the SASS to be import from external SASS file:

<style lang="scss" src="./styles.scss"></style>

Import a sass file from the top of the SFC sass file:

import '~mymodule/file.scss'

Would massively appreciate a fix for this, spent hours finding dead ends and broken code for what seems like a very common use case.

TODOs

The current API surface is the minimal amount of methods needed in vue-loader. There are a few features that are good to have here but not currently present:

CSS pre-processor handling in compileStyle

This is currently not included because in vue-loader CSS preprocessing is delegated to other webpack loaders. However for some other systems that do not support that kind of usage, directly handling preprocessors here will make more sense.

We will need to add the same preprocessLang and preprocessOptions fields to StyleCompileOptions. The implementation should look like the preprocess step in compileTemplate and be synchronous. It will require whatever preprocessor is specified in lang to be separately installed.

const { code, map } = compileStyle({
  source: `...`,
  filename: `...`,
  map: {},

  preprocessLang: styleDescriptor.lang,
  // optional extra options to be passed to the preprocessor
  preprocessOptions: {
    indentedSyntax: true
  }
})

compileScript for JavaScript pre-processor handling

This is left out because again vue-loader delegates script processing to webpack loaders. Same idea:

const { code, map } = compileScript({
  source: `...`,
  filename: `...`,
  map: {},

  preprocessLang: scriptDescriptor.lang,
  preprocessOptions: {
    // ...
  }
})

Actual compilation for babel, ts and coffee can probably be reused from vue-jest.

genId

Probably a good idea to put in this package as well.

assemble

This is intentionally left out because in actual implementations, the assemble step is highly dependent on the targeted system. Behaviors like hot reload and style injection have to be handled differently in different environments.

Tests

Currently this package has no tests for itself yet because most of the logic was tested during the development of vue-loader 15 and later simply moved into this package with minimal modifications.

But we surely need to write the tests :)

Higher-Level Convenience Method

The current vue-component-compiler package can be built on top of this package and expose an API that looks like this:

const templateCompiler = require('vue-template-compiler')
const { createCompiler } = require('vue-component-compiler')

const compiler = createCompiler({
  templateCompiler,
  templateCompilerOptions: {}, // optional
  transpileOptions: {}, // optional, for vue-template-es2015-compiler
  transformAssetUrls: true // optional, defaults to false
})

const compiledDescriptor = compiler.compile({
  source,
  filename,
  isProduction: true // optional, defaults to process.env.NODE_ENV === 'production'
})

Note the compile method returns a descriptor instead of code. The descriptor has the same template, script and style parts but contains compiled code and source maps. It is then up to the user to decide how to assemble these compiled descriptors into final code.

This API may or may not be flexible enough - but ideally tools like vue-jest should be able to use this API instead of the lower level ones.

/cc @znck @eddyerburgh

Update postcss

Please consider updating postcss to a version >= 8.2.13 since versions below are affected by Regular Expression Denial of Service.
See GHSA-566m-qj78-rww5 for more information.

Is the version of prettier necessary to be locked?

I just made a tool to make prettier works better with Vue SFC, which depends on @vue/component-compiler-utils.

I encountered an error when trying to resolve prettier's sharable config. I noticed that this feature was released in prettier v1.17.0, and my prettier is v1.18.x.

But when I inspected the lock file, I found that @vue/component-compiler-utils is using prettier as a denpendency, too, and locks the version to 1.16.3, which caused this error.

"prettier": "1.16.3",

Is the version of prettier necessary to be locked to 1.16.3?

About debugging components defined by the same name

Version

3.2.0

Reproduction link

https://github.com/crixusshen/vuecli-debug-reproduction

Environment info

Environment Info:

  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: Not Found
    npm: 6.14.5 - ~/.nvm/versions/node/v12.16.3/bin/npm
  Browsers:
    Chrome: 87.0.4280.88
    Edge: Not Found
    Firefox: Not Found
    Safari: 14.0
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1 
    @vue/babel-plugin-transform-vue-jsx:  1.2.1 
    @vue/babel-preset-app:  3.12.1 
    @vue/babel-preset-jsx:  1.2.4 
    @vue/babel-sugar-composition-api-inject-h:  1.2.1 
    @vue/babel-sugar-composition-api-render-instance:  1.2.4 
    @vue/babel-sugar-functional-vue:  1.2.2 
    @vue/babel-sugar-inject-h:  1.2.2 
    @vue/babel-sugar-v-model:  1.2.3 
    @vue/babel-sugar-v-on:  1.2.3 
    @vue/cli-overlay:  3.12.1 
    @vue/cli-plugin-babel: ^3.11.0 => 3.12.1 
    @vue/cli-plugin-eslint: ^3.11.0 => 3.12.1 
    @vue/cli-service: ^3.11.0 => 3.12.1 
    @vue/cli-shared-utils:  3.12.1 
    @vue/component-compiler-utils:  3.2.0 
    @vue/preload-webpack-plugin:  1.1.2 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.3 (4.7.1)
    vue: ^2.6.10 => 2.6.12 
    vue-eslint-parser:  2.0.3 (5.0.0)
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.5 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.10 => 2.6.12 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: 4.4.6

Steps to reproduce

I currently have two subcomponents with the same file name, although their implementations are different. Component A is located in 'src/components/A/HelloWorld.vue', Component B is located in 'src/components/B/HelloWorld.vue', although they are in A and B directories respectively, but their file names are called HelloWorld.vue.

Then use them separately in the main component:

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <HelloWorld2 msg="Welcome to Your React.js App"/>
  </div>
</template>

<script>
import HelloWorld from './components/A/HelloWorld.vue'
import HelloWorld2 from './components/B/HelloWorld.vue'

export default {
  name: 'app',
  components: {
    HelloWorld,
    HelloWorld2
  }
}
</script>

And then the view rendering is really expected.But I had trouble debugging in chrome.During debugging, I tried to debug A component, but I could only call out the implementation script of B component.At this point its debug path is located at โ€œwebpack:///HelloWorld.vue?hashโ€.

At this point I infer that as long as the component has the same name as the file name, the one after will override the one before when debugging.At that moment, on this basis and I create the src/components/C/HelloWorld.vue๏ผŒIt really confirmed my hypothesis.

This can cause a lot of trouble during debugging or problems where the debug file is not found.

What is expected?

Able to debug different files with the same name in debugging

What is actually happening?

currently only debug the last component in the same file name

Related issue

vuejs/vue-cli#4535

Allow for different transpilers than vue-template-es2015-compiler

Specifying a different transpiler than the current vue-template-es2015-compiler would add the ability for code inside the templates to be processed the same (or a similar) way to the code from <script>.

For example there are outstanding proposals to the ecmascript that currently can be used through babel plugins[1] but they won't work inside the template expressions since they don't follow the same compilation path.

[1] https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining

About adding a firstChar('@') in the templateCompilerModules/utils

 if (firstChar === '.' || firstChar === '~') {
            // when packaged in the browser, path will be using the posix-
            // only version provided by rollup-plugin-node-builtins.
            return `"${(path_1.default.posix || path_1.default).join(transformAssetUrlsOption.base, uriParts.path + (uriParts.hash || ''))}"`;
}

In the code above, can you add the ( firstChar === '@' ) ?

Using a function named "render" in a template breaks everything

Because of this line, if I have a template which includes something like {{render(data)}} I get weird errors in the console.

[Vue warn]: Error in render: "TypeError: _vm is undefined"

found in

---> <App>
       <Root> vue.runtime.esm.js:56:2
TypeError: "_vm is undefined"
render   http://localhost:1234/main.a1fcaaae.js:11645:7
render   http://localhost:1234/main.a1fcaaae.js:11659:24

Relevant lines in the generated JS source:

/* template */
        Object.assign($ec0164, (function () {
          var render = function() {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h
  return _c("div", { attrs: { id: "app" } }, [
    _vm._v("\n" + _vm._s(render(_vm.data)) + "\n")
  ])
}
var staticRenderFns = []
render._withStripped = true

          return {
            render: render,
            staticRenderFns: staticRenderFns,
            _compiled: true,
            _scopeId: null,
            functional: undefined
          };
        })());

As you can see, it is calling render(_vm.data) instead of _vm.render(_vm.data).

Does styleCompiler respect postcss config file?

I am using rollup-plugin-vue, and found it has its own postcss configuration item, and my postcss.config.js is not being read. After some investigation, I figured it out that styleCompiler this package requires it.

Is this intended? Or is it a better idea if compiler only extract css, and leave postcss processes to be handled by tools like postcss?

[Feature Request] Bump prettier version

Related issues:

Sorry for openning another issue, but I cannot get rid of the version inconsistency of prettier... ๐Ÿ˜ข

image

I know that could be an issue of yarn, but it would be better if we can bump the version of prettier...

TypeError: Cannot read property 'parseComponent' of undefined

After doing npm update, my npm run dev is throwing a bunch of instances of one error:

TypeError: Cannot read property 'parseComponent' of undefined
at parse (node_modules/@vue/component-compiler-utils/dist/parse.js:14:23)
at Object.module.exports (node_modules/vue-loader/lib/index.js:67:22)
@ ./resources/js/routes/index.js 18:11-28
@ ./resources/js/sp.js
@ multi ./resources/js/sp.js

The errors are all the same except for one difference: the reference 18:11-28 for ./resources/js/routes/index.js is different for each file. It looks like each error corresponds to an () => import() statement.

I would definitely appreciate some assistance on this since it's crashing my project's entire build.

optionalDependencies are installed as normal dependencies

This package declares prettier in optionalDependencies:

"optionalDependencies": {
"prettier": "^1.18.2"
}

I'm not sure if that was the intention, but when this @vue/component-compiler-utils is a dependency (or sub-dependency) in a given project, that optionalDependencies will be installed. And it's kinda pointless and unwanted to install prettier in my projects where I don't use it, I feel.

I know that I can use npm i --no-optional but that's a poor solution as nobody remembers to use it.

Also, I understand that it might not be desired to have prettier in peerDependencies as then it will trigger a warning when not installed.

Maybe just mention in the documentation that if you want to use prettier you have to add it manually?

Add License File

Our corporate compliance people have objections to us using projects without a full license text. It would be helpful if a license file could get added to this repo.

Fail to locate @import file "~@pkg/style.styl" in node_modules

Expected behavior

Expect to locate the .styl file from node_modules with ~ (which works well when bundled with Webpack)

<style lang="stylus" scoped>
@import '~@my-pkg/style.styl'
</style>

Actual behavior

Get the error:

failed to locate @import file ~@my-pkg/style.styl
    at Evaluator.visitImport (C:\Users\dev\node_modules\stylus\lib\visitor\evaluator.js:915:21)
    ...
    ...
    ...

However, when I import the .styl file with relative path:

<style lang="stylus">
@import '../node_modules/@my-pkg/style.styl'
</style>

It works fine.

Steps to reproduce the behavior

My rollup config:

import vue from 'rollup-plugin-vue'
import typescript from 'rollup-plugin-typescript2'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import json from 'rollup-plugin-json'

export default {
  input: 'src/index.vue',
  output: {
    format: 'esm',
    file: 'dist/bundle.esm.js'
  },
  plugins: [
    nodeResolve({
      jsnext: true,
      main: true
    }),
    commonjs(),
    json(),
    typescript({
      rollupCommonJSResolveHack: true,
      useTsconfigDeclarationDir: true
    }),
    vue()
  ]
}

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

// 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.

Switch `prettier` to an optional- or peerDependency

With the release of Prettier v2.x, projects wishing to update to the latest version will download both versions of Prettier due to this module having a hard dependency on v1.x.

Since Prettier is only require'd when prettify == true and NODE_ENV != "production", can this dependency be switched to an optionalDependency or peerDependency? Or perhaps its version requirement relaxed to include v2.x?

Cannot read property 'parseComponent' of undefined

I want to write a custom loader to process markdown format files,

web.config.js

module.exports = {
    configureWebpack: config => {
        config.module.rules.push({
            test: /\.md$/,
            use: [
                {
                    loader: 'vue-loader'
                },
                {
                    loader: require.resolve('./src/testLoader')
                }
            ]
        })
    }
}

testLoader.js

module.exports = function (value) {
    console.log(value)
    return "<template>" + value + "</template>"
}

HelloComponent.vue

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
import md from "./cx.md";
export default {
  name: "HelloWorld",
  components: {
    md,
  },
  props: {
    msg: String,
  },
};
</script>

The solution the search engine found was to keep the vue version and the version of the Ue-template-compiler consistent, but the vue version was 3.0 and the version of the Ue-template-compiler was the latest version 2.6.12.

 ERROR  Failed to compile with 3 errors                                                                                                                                                         9:58:20
 error  in ./src/components/HelloWorld.vue

Module Error (from ./node_modules/eslint-loader/index.js):

C:\Users\cx\Desktop\bao\demo3\src\components\HelloWorld.vue
  12:5  error  The "md" component has been registered but not used  vue/no-unused-components

โœ– 1 problem (1 error, 0 warnings)


 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=js 1:0-53 5:16-26
 @ ./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.13.2:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

 error  in ./src/components/cx.md

Module Error (from ./node_modules/vue-loader/lib/index.js):


Vue packages version mismatch:

- vue@3.0.0 (C:\Users\cx\Desktop\bao\demo3\node_modules\vue\index.js)
- vue-template-compiler@2.6.12 (C:\Users\cx\Desktop\bao\demo3\node_modules\vue-template-compiler\package.json)

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.


 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/HelloWorld.vue?vue&type=script&lang=js 1:0-25 5:8-10
 @ ./src/components/HelloWorld.vue?vue&type=script&lang=js
 @ ./src/components/HelloWorld.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.13.2:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

 error  in ./src/components/cx.md

Module build failed (from ./node_modules/vue-loader/lib/index.js):
TypeError: Cannot read property 'parseComponent' of undefined
    at parse (C:\Users\cx\Desktop\bao\demo3\node_modules\@vue\component-compiler-utils\dist\parse.js:14:23)
    at Object.module.exports (C:\Users\cx\Desktop\bao\demo3\node_modules\vue-loader\lib\index.js:67:22)

 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/HelloWorld.vue?vue&type=script&lang=js 1:0-25 5:8-10
 @ ./src/components/HelloWorld.vue?vue&type=script&lang=js
 @ ./src/components/HelloWorld.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.13.2:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
 

I saw a person raise this problem before, but according to the solution below, it cannot be solved
#82

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.