Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: rewrite asset with hash path, avoid name conflict
Browse files Browse the repository at this point in the history
fix: #81
  • Loading branch information
underfin committed May 29, 2021
1 parent 7f023f2 commit b5cf6b1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/template.ts
Expand Up @@ -4,6 +4,7 @@ import { TransformPluginContext } from 'rollup'
import { ResolvedOptions } from './index'
import { createRollupError } from './utils/error'
import { compileTemplate } from './template/compileTemplate'
import hash from 'hash-sum'

export function compileSFCTemplate(
source: string,
Expand All @@ -28,8 +29,8 @@ export function compileSFCTemplate(
...vueTemplateOptions,
compilerOptions: {
whitespace: 'condense',
...(vueTemplateOptions.compilerOptions || {})
}
...(vueTemplateOptions.compilerOptions || {}),
},
})

if (tips) {
Expand Down Expand Up @@ -75,10 +76,8 @@ export function transformRequireToImport(code: string): string {
/require\(("(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+')\)/g,
(_, name): any => {
if (!(name in imports)) {
imports[name] = `__$_require_${name
.replace(/[^a-z0-9]/g, '_')
.replace(/_{2,}/g, '_')
.replace(/^_|_$/g, '')}__`
// #81 compat unicode assets name
imports[name] = `__$_require_${hash(name)}__`
strImports += 'import ' + imports[name] + ' from ' + name + '\n'
}

Expand Down

0 comments on commit b5cf6b1

Please sign in to comment.