0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Nuxt3でのローカルJavaScriptグローバル読込み

Last updated at Posted at 2024-07-10

外部からダウンロードしてきた生のJSをNuxt3で使いたかった

結論

JSファイルをpublicフォルダ配下に置いて下記設定を行う

nuxt.config.ts
export default defineNuxtConfig({
  app: {
    head: {
      script: [{type: 'text/javascript', src: '/vender/hogefuga.js'}] // パスにpublicを含めない
    }
  }
})

以下はtscのエラー回避

tsconfig.json
{
  "exclude": ["./public/vender/*.js"]
}

経緯

普通に使いたいJSをインポートしようとしたら

useHogeFuga.ts
import './utils/hogefuga.js' 
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated

tscエラーとビルドエラーが発生:innocent:

strictモード中でdelete使うなよってこと

ベンダーソースを書き換えるわけにもいかないのでなんとかグローバルで読込み

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?