No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Importing and using external js libraries in quasar

    Help
    codemirror external import js library
    3
    6
    8077
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kageyasha last edited by

      As the topic says, I want to use a external js library (CodeMirror) in a component. The library consists multiple .js and .css files.
      My Component :

      <template>
        <div>
          <textarea name="cmds" id="cm"></textarea>
        </div>
      </template>
      
      <script>
      import codemirror from '../../src-extern/codemirror/codemirror.js'
      var editor = codemirror.fromTextArea(document.getElementById('cm'), {
        lineNumbers: true,
        autofocus: true,
        extraKeys: {
          'Ctrl-Space': 'autocomplete'
        }
      })
      export default {
        // name: 'ComponentName',
        data () {
          return {}
        },
        methods: {
          getCodeMirrorValue () {
            return editor.getValue()
          }
        }
      }
      </script>
      
      <style>
        #cm {
        border-style:solid;
        resize: none;
        height: 44vh;
        width: 100vw;
        }
      </style>
      
      

      But after starting my quasar/electron app I receive the following error :

       ./src/components/CodeMirror.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/CodeMirror.vue?vue&type=script&lang=js&) 2:13-23
      "export 'default' (imported as 'codemirror') was not found in '../../src-extern/codemirror/codemirror.js'
      

      The path is right and I know there is an npm package for codemirror but Im not able to use it due to some restrictions.
      Is there something im missing?

      qyloxe 1 Reply Last reply Reply Quote 0
      • qyloxe
        qyloxe @Kageyasha last edited by

        @Kageyasha you can add this to your package.json in “dependencies” section:

        “vue-codemirror”: “^4.0.6”,

        It is a Vue wrapper for CodeMirror and it works quite OK.

        K 1 Reply Last reply Reply Quote 0
        • K
          Kageyasha @qyloxe last edited by

          @qyloxe I would but unfortunately im not allowed to add any npm packages anymore due to some restrictions. I need to use the regular .js files

          qyloxe 1 Reply Last reply Reply Quote 0
          • qyloxe
            qyloxe @Kageyasha last edited by

            @Kageyasha said in Importing and using external js libraries in quasar:

            @qyloxe I would but unfortunately im not allowed to add any npm packages anymore due to some restrictions. I need to use the regular .js files

            vue-codemirror is open source and just a wrapper for codemirror itself. You can copy their code into your js files and maintain it yourself. Basically you need a wrapper component and this is what their component does. I assume you’re familiar with wrapper components:
            https://vuejs.org/v2/examples/select2.html

            K 1 Reply Last reply Reply Quote 0
            • K
              Kageyasha @qyloxe last edited by

              @qyloxe So is there no other way to import the required files from codemirror into my vue project(10x js files,4 css files) except using npm or building my own wrapper component? I know this is a very strange problem/request since its so easy to get it working with vue-codemirror… But the guy, who requested that kind of project doesnt want more npm modules into the project and I cant convince him.
              Somewhere I read that I can just link the “.js” files into the index.html of my vue/quasar project.
              Like that :

              <!DOCTYPE html>
              <html>
                <head>
                  <title><%= htmlWebpackPlugin.options.productName %></title>
              
                  <meta charset="utf-8">
                  <meta name="description" content="<%= htmlWebpackPlugin.options.productDescription %>">
                  <meta name="format-detection" content="telephone=no">
                  <meta name="msapplication-tap-highlight" content="no">
                  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width<% if (htmlWebpackPlugin.options.ctx.mode.cordova) { %>, viewport-fit=cover<% } %>">  
                  <link rel="icon" href="statics/quasar-logo.png" type="image/x-icon">
                  <link rel="icon" type="image/png" sizes="32x32" href="statics/icons/favicon-32x32.png">
                  <link rel="icon" type="image/png" sizes="16x16" href="statics/icons/favicon-16x16.png">
                  <script src="../src-extern/codemirror/codemirror.js"></script>
                    <link rel="stylesheet" href="../src-extern/codemirror/codemirror.css">
                </head>
                <body>
                  <!-- DO NOT touch the following DIV -->
                  <div id="q-app"></div>
                </body>
              </html>
              

              But after starting the APP (without using the library somewhere at all) I receive following error :

              (index):1 Refused to apply style from 'http://localhost:8080/src-extern/codemirror/codemirror.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
              
              codemirror.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
              
              (index):1 Refused to execute script from 'http://localhost:8080/src-extern/codemirror/codemirror.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
              
              (index):1 Refused to apply style from 'http://localhost:8080/src-extern/codemirror/codemirror.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
              

              Its an electron/quasar project btw. Maybe someone got a nice idea/workaround on how to get it into my project?

              1 Reply Last reply Reply Quote 0
              • patryckx
                patryckx last edited by patryckx

                It is not recommended to develop projects this way. But here is a solution I used to import files that I downloaded locally into the project.

                I put in my statics folder my js files, and imported it into template.html

                0e93f0d8-7507-4a67-8d6b-15b2a830a8a5-image.png

                3026c388-dbfa-439d-87d6-9f99c7b3dc75-image.png

                this way the webpack can solve the “statics” directory for me automatically

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post