Skip to content

add preprocessCustomRequire property and update types for options #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-plugin-vue3",
"version": "0.4.2",
"version": "0.4.3",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ const vuePlugin = (opts: Options = {}) => <esbuild.Plugin>{
(url: string) => ({ file: replaceRules(url) })
]
}, opts.preprocessorOptions),
preprocessCustomRequire : opts.preprocessorOptions ? opts.preprocessorOptions.preprocessCustomRequire : undefined,
scoped: style.scoped,
});

Expand Down
38 changes: 37 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { CompilerOptions, DirectiveNode, ElementNode, TransformContext } from "@vue/compiler-core";
import { IndexOptions } from "./html";

interface RawSourceMap {
file?: string
sourceRoot?: string
version: string
sources: string[]
names: string[]
sourcesContent?: string[]
mappings: string
}

type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus'

export type Options = {
/**
* Disable Options API support. Disabling this will result in smaller bundles,
Expand Down Expand Up @@ -92,6 +104,30 @@ export type Options = {
* Less: https://lesscss.org/usage/#less-options
*
* SCSS: https://sass-lang.com/documentation/js-api/interfaces/Options
*
* With version 0.4.3,you can now pass preprocessCustomRequire,
* this option is needed when this plugin is used on browser and
* you use a supported lang attribute on style tag.
* Check the links down below in order to understand what you need to pass
* https://github.com/vuejs/vue/blob/main/packages/compiler-sfc/src/compileStyle.ts
* https://github.com/vuejs/vue/blob/main/packages/compiler-sfc/src/stylePreprocessors.ts
*/
preprocessorOptions?: any; // any is the same type as compiler-sfc.d.ts allows it.
preprocessorOptions?: {
source: string
filename: string
id: string
scoped?: boolean
trim?: boolean
isProd?: boolean
inMap?: RawSourceMap
preprocessLang?: PreprocessLang
preprocessOptions?: any
preprocessCustomRequire?: (id: string) => any
postcssOptions?: any
postcssPlugins?: any[]
/**
* @deprecated use `inMap` instead.
*/
map?: RawSourceMap
} // types are taken from https://github.com/vuejs/core/tree/main/packages
}