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

    How to integrate python-webpack-loader?

    Help
    2
    5
    735
    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.
    • M
      mjmare last edited by

      Hi all,

      I’m trying to include python-wegpack-loader (https://github.com/martim00/python-webpack-loader) into the Quasar config.
      The goal is to use python in the Vue component’s script section. To this end the python-wegpack-loader uses the javascripthon transpiler to convert python to ES6.

      Even though I don’t really know what I’m doing I have partial success. I can import python scripts into my Vue components and call the code. Pretty cool already. However I have not achieved my goal of using only python within the script section of the component.

      This is my quasar.conf.js:

            extendWebpack (cfg) {
              cfg.module.rules.push({
                enforce: 'pre',
                test: /\.(js|vue)$/,
                loader: 'eslint-loader',
                exclude: /node_modules/
              });
              cfg.module.rules.push({
                enforce: 'pre',
                test: /\.py$/,
                loader: 'py-loader',
                options: {
                  compiler: 'pj'
                }
              });
              // cfg.module.rules.push({
              //   test: /\.vue$/,
              //   loader: 'vue-loader',
              //   options: {
              //     loaders: {
              //       'py': require.resolve('py-loader')
              //     }
              //   }
              // });
            }
      

      This works for the standalone python scripts (.py) but fails for this:

      <template>
        <div class="hello">
          <h1>{{ msg }}</h1>
        </div>
      </template>
      
      <script lang="py">
      class HelloWorld(object):
          name = 'HelloWorld'
          def data(self):
              return {'msg': 'Hello from Python!'}
      module.exports = HelloWorld()
      </script>
      

      The error is:

        11:15  error  Parsing error: Unexpected token, expected "{"
      
        1 | 
      > 2 | class Component:
          |                ^
        3 |   def __init__(self):
        4 |       self['data'] = lambda: { 'best_lang': 'Python' }
        5 | 
      

      I think this indicates that the python code is interpreted as javascript.
      I have tried to add a vue-loader section to quasar .conf.js (see commented out section above). Fails too.

      Any pointers on how to convince Quasar/Vue to use the python loader? It would be such a timesaver for me to be able to use python (you may pity me ;-).

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by s.molinari

        Don’t mean to be negative, but learning JavaScript would be easier. ducks and bows out of conversation 😄 :face_with_stuck-out_tongue_closed_eyes:

        Scott

        1 Reply Last reply Reply Quote 0
        • M
          mjmare last edited by mjmare

          Yeah, I’m trying, really. But coming from python JS is a mess. I’m really thankful for Quasar (and Vue) for enabling me to create a JS frontend. With some creative ESLint settings I can make it even make it look a bit like python. But since we are already compiling/transpiling all kinds of stuff, why not python? And I have the feeling I’m really close, but since I don’t really understand what’s going on with Webpack etc, I cannot make that final step.
          I’m sure other pythonistas would like to see something like this.

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by

            No matter what issues you are currently having with programming in JavaScript, you really should continue to learn the language. It isn’t hard and once you get the core concepts of JavaScript’s prototypal system (and don’t mix the “class” keyword with proper OOP classes either, which it sounds like you might be doing) and you learn its boundries and of course, its quirks, the language becomes quite liberating.

            If you stick to this path, I can see you scratching your head for a good long time trying to guess as to where a bug might be “stuck”, in the transpiling of your Python code to JavaScript, an error in your code, in the packages you are using or with the other technologies in the stack (like Webpack). It just isn’t a good idea, IMHO, to add extra uncertainty like that to your development process.

            Scott

            1 Reply Last reply Reply Quote 2
            • M
              mjmare last edited by

              Just biding my time until web assembly saves us all 😉

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