Skip to content

martim00/python-webpack-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Webpack Loader

Loads Python files and transpile to JavaScript using the awesome Transcrypt, Jiphy or Javascripthon compilers.

Install

pip install transcrypt  # or jiphy, or javascripthon
npm install --save-dev py-loader

You may specify jiphy instead of transcrypt if you prefer. In this case, ensure that options.compiler in webpack.config.js is set to jiphy (see below). The compiler option for Javascripthon is pj.

Usage

import Something from 'main.py';

Configuration

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.py$/,
        loader: 'py-loader',
        options: {
          compiler: 'transcrypt'
        }
      }
    ]
  }
}

VueJS support

py-loader can also be used to compile .vue Single File Components used by VueJS. This assumes that you already have vue-loader set up and working with javascript .vue files. Modify your vue-loader config file as shown:

  loaders: {
    'py': require.resolve('py-loader')
  },

An example of a simple VueJS app written in (mostly) Python can be seen in the examples/vue-demo folder.

Caveats

  • Only tested with Transcrypt
  • The import statement for loading sub-components still looks a bit weird
  • Web-pack entry point is still a javascript file

Extend

py-loader can be extended to use other Python compilers. Just fork this repo and extend the compilers object in index.js.

Please submit a pull request with your addition.

Contributors

About

A webpack loader for the python language

Resources

Stars

Watchers

Forks

Packages

No packages published