Skip to content

How to import all files in a directory into build? #760

Closed Answered by aiktb
aiktb asked this question in Q&A
Discussion options

You must be logged in to vote

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.
But there are a few things to be aware of:

  1. The behavior of chrome.runtime.getURL(path) is very strange. I have to write const path = '../assets/dict' to use fetch normally.
  2. The normal operation of '../../assets/dict' depends on the directory structure generated by build to be static/background/index.js. If this is src/background/index.ts, obviously I…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by aiktb
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant