Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Commit 71d4b64

Browse files
authored
Remove loader-utils dependency (#6)
1 parent 3ee133f commit 71d4b64

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,5 @@
7676
"vue": "3.2.20",
7777
"vue-loader": "16.8.2",
7878
"webpack": "5.61.0"
79-
},
80-
"dependencies": {
81-
"loader-utils": "^2.0.0"
8279
}
8380
}

pnpm-lock.yaml

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type { LoaderDefinitionFunction } from 'webpack/types'
22

3-
import { parseQuery, OptionObject } from 'loader-utils'
4-
5-
function generateCode (rawData: string, query: OptionObject, hot = false): string {
3+
function generateCode (rawData: string, query: URLSearchParams, hot = false): string {
64
// vue-loader pads SFC file sections with newlines - trim those
75
const data = rawData.replace(/^(\n|\r\n)+|(\n|\r\n)+$/g, '')
86

9-
if (typeof query.locale !== 'string') {
7+
const locale = query.get('locale')
8+
if (typeof locale !== 'string') {
109
throw new Error('Custom block does not have locale attribute')
1110
}
1211

@@ -33,14 +32,15 @@ import { FluentResource } from '@fluent/bundle'
3332
export default function (Component) {
3433
const target = Component.options || Component
3534
target.fluent = target.fluent || {}
36-
target.fluent['${query.locale}'] = new FluentResource(\`${data}\`)
35+
target.fluent['${locale}'] = new FluentResource(\`${data}\`)
3736
${hotCode}
3837
}\n`
3938
}
4039

4140
const loader: LoaderDefinitionFunction = function (this, source, sourceMap) {
4241
try {
43-
this.callback(null, generateCode(source, parseQuery(this.resourceQuery), this.hot), sourceMap)
42+
const options = new URLSearchParams(this.resourceQuery.slice(1))
43+
this.callback(null, generateCode(source, options, this.hot), sourceMap)
4444
} catch (err) {
4545
this.emitError(err as Error)
4646
this.callback(err as Error)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy