Skip to content

3.7 import issues with webpack #517

Open
@doconix

Description

@doconix

(btw, the new 3.7 structure rocks. It is much prettier to put the runtime in a separate file.)

I'm using the new 3.7 with webpack using py-loader. I'm modifying py-loader for the 3.7 , but there is one issue that I'm not sure how to solve.

We need to solve it "correctly" so py-loader and transcrypt work together for all users on webpack. I don't want to pretend that my setup is super important compared to others, but I would argue that making transcrypt work really well within webpack is very important to its wider adoption. Webpack makes transcrypt seamless because we can import the .py file directly (see below) instead of the transpiled .js file. All transpiling is totally transparent.

Let me see if I can explain the issue clearly. Suppose I import a transcrypt file in a JS file called main.js:

import { something } from './module.py'

When webpack sees this import, it uses py-loader to call transcrypt. This results in the following:

./main.js
./module.py
./__target__/module.js
./__target__/org.transcrypt.__runtime__.js

webpack doesn't use the compiled module.js from the disk. It instead pipes the contents of module.js from py-loader directly. The current directory is still ./, not the subdirectory. This worked fine in the old Transcrypt because everything was in one file.

However, since the runtime is in a separate file (and imported into module.js), webpack can't find the runtime file. To be clear, webpack needs this directory structure:

./main.js
./module.py
./module.js
./org.transcrypt.__runtime__.js

(the module.js file actually doesn't matter because it gets streamed).

Possible solutions I can think of:

  1. Include the runtime manually in my webpack config somehow. The issue here is the current directory may not be the right place to import the runtime vars from. That line is hard coded into transcrypt.
  2. Make the __target__ subdirectory name be configurable. That way I can have all the files output to the current directory (i.e. no subdir).
  3. Have py-loader copy the runtime to the current directory. This is a bit of a hack but will work.

#1 above is the best solution, IMO, because it allows me to include the runtime once in my entire project and then reference the single runtime js file from all the modules. I'm not sure how to do this, though, because the modules could be in any directory of my project, and ES6 imports have to be relative.

Ideas?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions