React-ace: ์ฝ˜์†” ์˜ค๋ฅ˜, ๊ตฌ์„ฑ ์š”์†Œ ์ž‘๋™ ๋ฐฉ์‹์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์งœ์ฆ๋‚˜.

์— ๋งŒ๋“  2020๋…„ 02์›” 11์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: securingsincity/react-ace

๋ฌธ์ œ

์—ฌ๋Ÿฌ ๋ชจ๋“œ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1 Refused to execute script from 'http://localhost:3000/worker-css.js' because its MIME type ('text/html') is not executable.
(anonymous) @ a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1
a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:3000/worker-css.js' failed to load.
    at blob:http://localhost:3000/a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1:1

์ด ์˜ค๋ฅ˜๋Š” ์•„๋ฌด ๊ฒƒ๋„ ๋ง์น˜์ง€ ์•Š์œผ๋ฉฐ ๋ชจ๋“  ๊ฒƒ์ด ์ž‘๋™ํ•˜๋ฉฐ ๋ชจ๋“œ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
์‚ฌ์šฉ์ž์—๊ฒŒ ๋‹ค์–‘ํ•œ ๋ชจ๋“œ(css, javascript, python ๋“ฑ)๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒ๊ธฐ ๋ชฉ๋ก์—์„œ ์š”์ฒญํ•œ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ๋ชจ๋“œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ๋ฅผ ์žฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์ƒ˜ํ”Œ ์ฝ”๋“œ

// This runs whenever a new mode is selected by the user
    const handleModeChange = (event) => {
      var currentMode = event.target.value;
      require(`ace-builds/src-noconflict/mode-${currentMode}`)
      setState({...state, currentMode})
    }


            <AceEditor
              mode={state.currentMode}
              width="100%"
              theme="twilight"
              value={state.code}
              onChange={onChange}
              name="code_editor"
              editorProps={{ $blockScrolling: true }}
            /> 

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

ํ•ด๊ฒฐ์ฑ…:

import "ace-builds/webpack-resolver" ์ถ”๊ฐ€ํ•œ ํ›„ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
https://github.com/securingsincity/react-ace/issues/725#issuecomment -543109155 ์ฐธ์กฐ

๋ชจ๋“  3 ๋Œ“๊ธ€

๋™์ผํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•จ

import AceEditor from "react-ace"

import "ace-builds/src-noconflict/mode-javascript"
import "ace-builds/src-noconflict/theme-monokai"
//...
  <AceEditor
      name="Ace-editor"
      mode="javascript"
      fontSize={15}
      wrapEnabled={true}
      value={beautify(JSON.stringify(state.stepDetails))}
      theme="monokai"
      onChange={handleSchemaChange}
      enableBasicAutocompletion={true}
      enableLiveAutocompletion={true}
      editorProps={{ $blockScrolling: true }}
    />

ํ•ด๊ฒฐ์ฑ…:

import "ace-builds/webpack-resolver" ์ถ”๊ฐ€ํ•œ ํ›„ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
https://github.com/securingsincity/react-ace/issues/725#issuecomment -543109155 ์ฐธ์กฐ

@pi0neerpat ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰