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

Remove loader-utils dependency #6

Merged
merged 1 commit into from
Oct 31, 2021
Merged
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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,5 @@
"vue": "3.2.20",
"vue-loader": "16.8.2",
"webpack": "5.61.0"
},
"dependencies": {
"loader-utils": "^2.0.0"
}
}
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { LoaderDefinitionFunction } from 'webpack/types'

import { parseQuery, OptionObject } from 'loader-utils'

function generateCode (rawData: string, query: OptionObject, hot = false): string {
function generateCode (rawData: string, query: URLSearchParams, hot = false): string {
// vue-loader pads SFC file sections with newlines - trim those
const data = rawData.replace(/^(\n|\r\n)+|(\n|\r\n)+$/g, '')

if (typeof query.locale !== 'string') {
const locale = query.get('locale')
if (typeof locale !== 'string') {
throw new Error('Custom block does not have locale attribute')
}

Expand All @@ -33,14 +32,15 @@ import { FluentResource } from '@fluent/bundle'
export default function (Component) {
const target = Component.options || Component
target.fluent = target.fluent || {}
target.fluent['${query.locale}'] = new FluentResource(\`${data}\`)
target.fluent['${locale}'] = new FluentResource(\`${data}\`)
${hotCode}
}\n`
}

const loader: LoaderDefinitionFunction = function (this, source, sourceMap) {
try {
this.callback(null, generateCode(source, parseQuery(this.resourceQuery), this.hot), sourceMap)
const options = new URLSearchParams(this.resourceQuery.slice(1))
this.callback(null, generateCode(source, options, this.hot), sourceMap)
} catch (err) {
this.emitError(err as Error)
this.callback(err as Error)
Expand Down
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