Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/vue-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v16.8.3
Choose a base ref
...
head repository: vuejs/vue-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v17.0.0
Choose a head ref
  • 5 commits
  • 15 files changed
  • 2 contributors

Commits on Nov 4, 2021

  1. chore: 16.8.3 changelog

    haoqunjiang committed Nov 4, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    haoqunjiang Haoqun Jiang
    Copy the full SHA
    5a13fa2 View commit details

Commits on Nov 26, 2021

  1. Copy the full SHA
    b391b04 View commit details

Commits on Dec 12, 2021

  1. feat: support reactivityTransform option

    BREAKING CHANGE: remove `refSugar` option, require `vue@^3.2.13`
    yyx990803 committed Dec 12, 2021
    Copy the full SHA
    e07490e View commit details
  2. chore: lockfile

    yyx990803 committed Dec 12, 2021
    Copy the full SHA
    e931434 View commit details
  3. v17.0.0

    yyx990803 committed Dec 12, 2021
    Copy the full SHA
    e5c7ab4 View commit details
Showing with 135 additions and 319 deletions.
  1. +9 −0 CHANGELOG.md
  2. +4 −2 README.md
  3. +1 −2 example/webpack.config.js
  4. +2 −3 package.json
  5. +2 −2 src/compiler.ts
  6. +3 −3 src/descriptorCache.ts
  7. +3 −7 src/formatError.ts
  8. +0 −2 src/hotReload.ts
  9. +4 −4 src/index.ts
  10. +20 −29 src/resolveScript.ts
  11. +1 −1 src/select.ts
  12. +2 −2 src/stylePostLoader.ts
  13. +3 −3 src/templateLoader.ts
  14. +1 −1 src/util.ts
  15. +80 −258 yarn.lock
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [16.8.3](https://github.com/vuejs/vue-loader/compare/v16.8.2...v16.8.3) (2021-11-04)


### Bug Fixes

* HMR not working correctly with vue-class-component components ([#1897](https://github.com/vuejs/vue-loader/issues/1897)) ([76b1448](https://github.com/vuejs/vue-loader/commit/76b1448eb227c42e1791a691a86782b7a8cacfc0))



## [16.8.2](https://github.com/vuejs/vue-loader/compare/v16.8.1...v16.8.2) (2021-10-26)


6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@
- [Documentation](https://vue-loader.vuejs.org)

## v16 Only Options
## v16+ Only Options

- `refSugar: boolean`: enable experimental ref sugar.
- `reactivityTransform: boolean`: enable [Vue Reactivity Transform](https://github.com/vuejs/rfcs/discussions/369) (SFCs only).

- ~~`refSugar: boolean`: **removed.** use `reactivityTransform` instead.~~

- `customElement: boolean | RegExp`: enable custom elements mode. An SFC loaded in custom elements mode inlines its `<style>` tags as strings under the component's `styles` option. When used with `defineCustomElement` from Vue core, the styles will be injected into the custom element's shadow root.

3 changes: 1 addition & 2 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -54,8 +54,7 @@ module.exports = (env = {}) => {
test: /\.vue$/,
loader: 'vue-loader',
options: {
refSugar: true,
// enableTsInTemplate: false,
reactivityTransform: true,
},
},
{
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
"version": "16.8.3",
"version": "17.0.0",
"license": "MIT",
"author": "Evan You",
"main": "dist/index.js",
@@ -51,7 +51,6 @@
"@types/mini-css-extract-plugin": "^0.9.1",
"@types/webpack": "^4.41.0",
"@types/webpack-merge": "^4.1.5",
"@vue/compiler-sfc": "^3.2.12",
"babel-loader": "^8.1.0",
"cache-loader": "^4.1.0",
"conventional-changelog-cli": "^2.1.1",
@@ -81,7 +80,7 @@
"ts-loader-v9": "npm:ts-loader@^9.2.4",
"typescript": "^4.4.3",
"url-loader": "^4.1.0",
"vue": "^3.2.13",
"vue": "^3.2.25",
"vue-i18n": "^9.1.7",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
4 changes: 2 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// extend the descriptor so we can store the scopeId on it
declare module '@vue/compiler-sfc' {
declare module 'vue/compiler-sfc' {
interface SFCDescriptor {
id: string
}
}

import * as _compiler from '@vue/compiler-sfc'
import * as _compiler from 'vue/compiler-sfc'

export let compiler: typeof _compiler

6 changes: 3 additions & 3 deletions src/descriptorCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs'
import type { SFCDescriptor } from '@vue/compiler-sfc'
import { compiler } from './compiler'
import type { SFCDescriptor } from 'vue/compiler-sfc'
import { parse } from 'vue/compiler-sfc'

const cache = new Map<string, SFCDescriptor>()

@@ -20,7 +20,7 @@ export function getDescriptor(filename: string): SFCDescriptor {
// loaders being run in separate threads. The only way to deal with this is to
// read from disk directly...
const source = fs.readFileSync(filename, 'utf-8')
const { descriptor } = compiler.parse(source, {
const { descriptor } = parse(source, {
filename,
sourceMap: true,
})
10 changes: 3 additions & 7 deletions src/formatError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompilerError } from '@vue/compiler-sfc'
import { compiler } from './compiler'
import type { CompilerError } from 'vue/compiler-sfc'
import { generateCodeFrame } from 'vue/compiler-sfc'
import chalk = require('chalk')

export function formatError(
@@ -13,11 +13,7 @@ export function formatError(
}
const locString = `:${loc.start.line}:${loc.start.column}`
const filePath = chalk.gray(`at ${file}${locString}`)
const codeframe = compiler.generateCodeFrame(
source,
loc.start.offset,
loc.end.offset
)
const codeframe = generateCodeFrame(source, loc.start.offset, loc.end.offset)
err.message = `\n${chalk.red(
`VueCompilerError: ${err.message}`
)}\n${filePath}\n${chalk.yellow(codeframe)}\n`
2 changes: 0 additions & 2 deletions src/hotReload.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ if (module.hot) {
const api = __VUE_HMR_RUNTIME__
module.hot.accept()
if (!api.createRecord('${id}', __exports__)) {
console.log('reload')
api.reload('${id}', __exports__)
}
${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
@@ -22,7 +21,6 @@ if (module.hot) {
function genTemplateHotReloadCode(id: string, request: string) {
return `
module.hot.accept(${request}, () => {
console.log('re-render')
api.rerender('${id}', render)
})
`
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ import * as loaderUtils from 'loader-utils'

import hash = require('hash-sum')

import { compiler } from './compiler'
import { parse } from 'vue/compiler-sfc'
import type {
TemplateCompiler,
CompilerOptions,
SFCBlock,
SFCTemplateCompileOptions,
SFCScriptCompileOptions,
} from '@vue/compiler-sfc'
} from 'vue/compiler-sfc'
import { selectBlock } from './select'
import { genHotReloadCode } from './hotReload'
import { genCSSModulesCode } from './cssModules'
@@ -30,7 +30,7 @@ export interface VueLoaderOptions {
transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls']
compiler?: TemplateCompiler | string
compilerOptions?: CompilerOptions
refSugar?: boolean
reactivityTransform?: boolean
customElement?: boolean | RegExp

hotReload?: boolean
@@ -88,7 +88,7 @@ export default function loader(
mode === 'production' || process.env.NODE_ENV === 'production'

const filename = resourcePath.replace(/\?.*$/, '')
const { descriptor, errors } = compiler.parse(source, {
const { descriptor, errors } = parse(source, {
filename,
sourceMap,
})
49 changes: 20 additions & 29 deletions src/resolveScript.ts
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ import type {
SFCDescriptor,
SFCScriptBlock,
TemplateCompiler,
} from '@vue/compiler-sfc'
} from 'vue/compiler-sfc'
import type { VueLoaderOptions } from 'src'
import { resolveTemplateTSOptions } from './util'
import { compiler } from './compiler'
import { compileScript } from 'vue/compiler-sfc'

const clientCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
const serverCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
@@ -53,34 +53,25 @@ export function resolveScript(
templateCompiler = options.compiler
}

if (compiler.compileScript) {
try {
resolved = compiler.compileScript(descriptor, {
id: scopeId,
isProd,
inlineTemplate: enableInline,
refSugar: options.refSugar,
babelParserPlugins: options.babelParserPlugins,
templateOptions: {
ssr: isServer,
compiler: templateCompiler,
compilerOptions: {
...options.compilerOptions,
...resolveTemplateTSOptions(descriptor, options),
},
transformAssetUrls: options.transformAssetUrls || true,
try {
resolved = compileScript(descriptor, {
id: scopeId,
isProd,
inlineTemplate: enableInline,
reactivityTransform: options.reactivityTransform,
babelParserPlugins: options.babelParserPlugins,
templateOptions: {
ssr: isServer,
compiler: templateCompiler,
compilerOptions: {
...options.compilerOptions,
...resolveTemplateTSOptions(descriptor, options),
},
})
} catch (e) {
loaderContext.emitError(e)
}
} else if (descriptor.scriptSetup) {
loaderContext.emitError(
`<script setup> is not supported by the installed version of ` +
`@vue/compiler-sfc - please upgrade.`
)
} else {
resolved = descriptor.script
transformAssetUrls: options.transformAssetUrls || true,
},
})
} catch (e) {
loaderContext.emitError(e)
}

cacheToUse.set(descriptor, resolved)
2 changes: 1 addition & 1 deletion src/select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import webpack = require('webpack')
import type { SFCDescriptor } from '@vue/compiler-sfc'
import type { SFCDescriptor } from 'vue/compiler-sfc'
import type { ParsedUrlQuery } from 'querystring'
import { resolveScript } from './resolveScript'
import type { VueLoaderOptions } from 'src'
4 changes: 2 additions & 2 deletions src/stylePostLoader.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as qs from 'querystring'
import { compiler } from './compiler'
import webpack = require('webpack')
import { compileStyle } from 'vue/compiler-sfc'

// This is a post loader that handles scoped CSS transforms.
// Injected right before css-loader by the global pitcher (../pitch.js)
// for any <style scoped> selection requests initiated from within vue files.
const StylePostLoader: webpack.loader.Loader = function (source, inMap) {
const query = qs.parse(this.resourceQuery.slice(1))
const { code, map, errors } = compiler.compileStyle({
const { code, map, errors } = compileStyle({
source: source as string,
filename: this.resourcePath,
id: `data-v-${query.id}`,
6 changes: 3 additions & 3 deletions src/templateLoader.ts
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ import * as qs from 'querystring'
import * as loaderUtils from 'loader-utils'
import { VueLoaderOptions } from './'
import { formatError } from './formatError'
import type { TemplateCompiler } from '@vue/compiler-sfc'
import type { TemplateCompiler } from 'vue/compiler-sfc'
import { getDescriptor } from './descriptorCache'
import { resolveScript } from './resolveScript'
import { resolveTemplateTSOptions } from './util'
import { compiler } from './compiler'
import { compileTemplate } from 'vue/compiler-sfc'

// Loader that compiles raw template into JavaScript functions.
// This is injected by the global pitcher (../pitch) for template
@@ -42,7 +42,7 @@ const TemplateLoader: webpack.loader.Loader = function (source, inMap) {
templateCompiler = options.compiler
}

const compiled = compiler.compileTemplate({
const compiled = compileTemplate({
source,
filename: loaderContext.resourcePath,
inMap,
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SFCDescriptor, CompilerOptions } from '@vue/compiler-sfc'
import type { SFCDescriptor, CompilerOptions } from 'vue/compiler-sfc'
import type { VueLoaderOptions } from '.'

export function resolveTemplateTSOptions(
Loading