Skip to content

Commit c3cb205

Browse files
committed
Make pj default. Options in nuxt.config.js.
1 parent f0cdcee commit c3cb205

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@
2626
```
2727
3. Run example: `npm run dev`
2828
29-
## Setup
29+
## Setup in your own project
30+
3031
- Add `@nuxtjs/python` dependency using yarn or npm to your project
3132
- Add `@nuxtjs/python` to `modules` section of `nuxt.config.js`
32-
33-
```js
34-
{
35-
modules: [
36-
// Simple usage
37-
'@nuxtjs/python'
38-
]
39-
}
40-
```
33+
```js
34+
{
35+
modules: [
36+
'@nuxtjs/python'
37+
],
38+
python: {
39+
compiler: 'pj' // default
40+
}
41+
}
42+
```
43+
- In Vue files, Mark your script tags like this: `<script lang="py">`.
44+
- You may pass options to py-loader (currently it supports `compiler` parameter)
45+
46+
## Choice of Python to Javascript compiler
47+
48+
Compiler default and recommended is **Javascripthon** but it is possible to use other compilers (see below).
4149

4250
- Install the [Javascripthon](https://gitlab.com/metapensiero/metapensiero.pj) Python transpiler. For now **you'll need the master branch** e.g:
4351
```
@@ -46,15 +54,17 @@
4654
4755
- Note that Javascripthon requires that you have **Python 3.5** (or better).
4856
49-
- In Vue files, Mark your script tags like this: `<script lang="py?compiler=pj">`.
57+
- Javascripthon supports converting Python import statements to ES6 imports as used in Nuxt. Please note syntax [conversions](https://gitlab.com/metapensiero/metapensiero.pj#import-statements).
58+
59+
- You can pass a `compiler` option to py-loader by using module options or in a `python` section in your `nuxt.config.js` file.
5060
51-
- Please note syntax [conversions](https://gitlab.com/metapensiero/metapensiero.pj#import-statements).
61+
- `Transcrypt` has its own module system so in order to use it, you can use the CommonJS module standard (`require` to import and `module.exports`) and it should work. See the `py-loader` [Vuejs example](https://github.com/martim00/python-webpack-loader/blob/master/examples/vue-demo/src/App.vue).
5262
5363
## Usage
5464
5565
### Using `.vue` files
5666
57-
**TIP** If you use Vim you can get the full experience with https://github.com/posva/vim-vue/pull/97
67+
**TIP** If you use Vim you can get syntax highlighting for HTML, CSS *and* Python by installing [vim-vue](https://github.com/posva/vim-vue) plugin and applying [this patch](https://github.com/posva/vim-vue/pull/97).
5868
5969
`hello.vue`:
6070
@@ -65,7 +75,7 @@
6575
</div>
6676
</template>
6777
68-
<script lang="py?compiler=pj">
78+
<script lang="py">
6979
class Component:
7080
def __init__(self):
7181
self['data'] = lambda: { 'best_lang': 'Python' }

example/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</section>
2626
</template>
2727

28-
<script lang="py?compiler=pj">
28+
<script lang="py">
2929
from ..components.PythonLogo import __default__ as PythonLogo
3030
from ..components.NuxtLogo import __default__ as NuxtLogo
3131

lib/module.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
module.exports = function PythonModule (moduleOptions) {
2+
var options = Object.assign({}, this.options.python, moduleOptions)
3+
4+
if (options.compiler === undefined) {
5+
options.compiler = 'pj'
6+
}
7+
28
this.nuxt.options.extensions.push('py')
39

410
this.extendBuild((config, { isClient, isServer }) => {
511
config.devtool = '#cheap-module-eval-source-map'
612
config.resolve.extensions.push('.py')
13+
14+
const vueLoader = config.module.rules.find((rule) => rule.loader === 'vue-loader')
15+
vueLoader.options.loaders.py = { loader: 'py-loader',
16+
options: options }
17+
718
config.module.rules.push({
819
test: /\.py$/,
920
loader: 'py-loader',
10-
options: {
11-
compiler: 'pj'
12-
}
21+
options: options
1322
})
1423
})
1524
}
25+
26+
module.exports.meta = require('../package.json')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nuxtjs/python",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Write Nuxt.js Apps in Python",
55
"license": "MIT",
66
"contributors": [

0 commit comments

Comments
 (0)