8000 chore: refactor hash() by Jinjiang · Pull Request #2062 · vuejs/vue-loader · GitHub
[go: up one dir, main page]

Skip to content
8000

chore: refactor hash() #2062

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

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8000
Diff view
Diff view
Next Next commit
refactor: align hash() with vite plugin
  • Loading branch information
Jinjiang committed Jan 10, 2024
commit a1c4cc11352428cbf9754c24903c263404cda3d8
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { LoaderContext } from 'webpack'
import * as path from 'path'
import * as crypto from 'crypto'
import * as qs from 'querystring'

import hash = require('hash-sum')

import { compiler } from './compiler'
import type {
TemplateCompiler,
Expand Down Expand Up @@ -66,6 +65,10 @@ let errorEmitted = false
const { parse } = compiler
const exportHelperPath = require.resolve('./exportHelper')

function hash(text: string): string {
return crypto.createHash('sha256').update(text).digest('hex').substring(0, 8)
}

export default function loader(
this: LoaderContext<VueLoaderOptions>,
source: string
Expand Down
6 changes: 5 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* env jest */
import * as path from 'path'
import * as crypto from 'crypto'
import webpack from 'webpack'
import merge from 'webpack-merge'
import hash from 'hash-sum'
// import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { fs as mfs } from 'memfs'
import { JSDOM, VirtualConsole } from 'jsdom'
import { VueLoaderPlugin } from '..'
import type { VueLoaderOptions } from '..'

function hash(text: string): string {
return crypto.createHash('sha256').update(text).digest('hex').substring(0, 8)
}

export const DEFAULT_VUE_USE = {
loader: 'vue-loader',
options: {
Expand Down
0