-
I need the *.dat.gz files in the assets/dict directory, but they are not automatically packaged into assets, how can I do this? import kuromoji from '@sglkc/kuromoji'
import type { PlasmoMessaging } from '@plasmohq/messaging'
import type { MojiToken } from '~contents/kanjiTokenizer'
const handler: PlasmoMessaging.MessageHandler<
{ text: string },
{ message: MojiToken[] }
> = async (req, res) => {
const tokenizer = kuromoji.builder({ dicPath: 'assets/dict' })
tokenizer.build((_err, tokenizer) => {
const message: MojiToken[] = tokenizer.tokenize(req.body!.text)
res.send({ message })
})
}
export default handler |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
package.json "manifest": {
"web_accessible_resources": [
{
"resources": [
"assets/dict/*.dat.gz"
],
"matches": [
"https://*/*"
]
}
]
} src/background/messages/tokenizer.ts const tokenizer = kuromoji.builder({ dicPath: '../../assets/dict' }) This will solve the problem.
|
Beta Was this translation helpful? Give feedback.
-
I now realise that Service Worker does not have access to "web_accessible_resources"! |
Beta Was this translation helpful? Give feedback.
package.json
src/background/messages/tokenizer.ts
This will solve the problem.
But there are a few things to be aware of:
chrome.runtime.getURL(path)
is very strange. I have to writeconst path = '../assets/dict'
to use fetch normally.'../../assets/dict'
depends on the directory structure generated by build to bestatic/background/index.js
. If this issrc/background/index.ts
, obviously I…