0.3.1 • Published 3 months ago

@liip/esbuild-plugin-ast-vue v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

esbuild-plugin-ast-vue

A plugin to generate an AST representation of your .vue files. The plugin use Acorn to produce an estree compliant AST object. You can then apply transformations by providing a visitor object. In order to also parse your .js dependencies imported in your scripts, you should probably use the @liip/esbuild-plugin-ast in conjunction with this plugin since esbuild does not allow plugin composition.

Installation

npm i -D @liip/esbuild-plugin-ast-vue @liip/esbuild-plugin-ast

Usage

import { astParser } from '@liip/esbuild-plugin-ast';
import { astParserVue } from '@liip/esbuild-plugin-ast-vue';

...

await esbuild.context({
  ...
  plugins: [astParserVue(vueParserOptions), astParser(parserOptions)],
  ...
});

...

Options

You can configure the way the plugin works by setting different options.

interface AstParserVueOptions extends AstParserOptions {
  scriptNamespace?: string;
  templateVisitor: AstParserOptions['visitor'];
  templateOptions?: Pick<
    SFCTemplateCompileOptions,
    | 'compiler'
    | 'preprocessLang'
    | 'preprocessOptions'
    | 'compilerOptions'
    | 'transformAssetUrls'
  >;
  scriptOptions?: Pick<SFCScriptCompileOptions, 'babelParserPlugins'>;
  styleOptions?: Pick<
    SFCAsyncStyleCompileOptions,
    | 'modulesOptions'
    | 'preprocessLang'
    | 'preprocessOptions'
    | 'postcssOptions'
    | 'postcssPlugins'
  >;
}

scriptNamespace

A string namespace used to tell @liip/esbuild-plugin-ast to parse .js dependencies from your .vue files. This is required since esbuild does not allow plugin composition. This namespace should also be provided to astParser in order to work correctly.

visitor

An ESTraverse.Visitor object used to apply AST transformations. Check the Estraverse documentation form more information on the available API.

templateVisitor

An ESTraverse.Visitor object used to apply AST transformations to the JavaScript produce by the template interpretation. Check the Estraverse documentation form more information on the available API.

templateOptions

Template options passed to the underlying SFCCompiler. See the compileTemplate.ts implementation for more details

scriptOptions

Script options passed to the underlying SFCCompiler. See the compileScript.ts implementation for more details

styleOptions

Style options passed to the underlying SFCCompiler. See the compileStyle.ts implementation for more details

0.3.1

3 months ago

0.3.0

7 months ago

0.2.0

7 months ago

0.1.1

10 months ago

0.1.0

10 months ago