Can I use JSPM without a transpiler?

2019-06-15 02:54发布

I am using jspm 0.16.2.

I am using this test project

When I set the Transpiler to none: transpiler: "none"

I get an error XHR error (404 Not Found) loading http://localhost:53404/none.js

If I set the transpiler to 'test' it gives the same error, except for it looks for test.js

Is this a bug with jspm?

I wanted to not use a transpiler, but use system.js to load AMD modules.

When I removed the transpiler option from config.js, then it tries to load Traceur.

I would like to not have a Transpiler running at runtime.

标签: jspm
1条回答
对你真心纯属浪费
2楼-- · 2019-06-15 03:22

It's not clear what you're trying to do. If you use ES2015 features (e.g. ES2015 modules, let, etc.), then you need the transpiler. If you write your code with no ES2015 features, then no transpiler will be loaded. You can check this by putting ES5 code in main.js and checking the Network tab of your debugger. browser.js will not be downloaded.

The string you put in for transpiler in System.config is literally the transpiler file itself. In the case of "babel", it is mapped to npm:babel-core@5.8.3 (from map field) which when combined with the path field refers to jspm_packages/npm/babel-core@5.8.3 and then in that directory, the file .jspm.json points the entry point to browser.js, which is the client side transpiler file itself.

Whatever string you set transpiler to, jspm will set up System to point to it (the path will just be the baseURL if you haven't mapped it) and fetch it. Of course it's not there for any arbitrary string such as none or test. The default, if you don't specify anything, as you've observed is traceur.

You do have the option of transpiling server side by doing jspm bundle if client side transipling is what you're trying to avoid.

For code that uses only ES5 and AMD, without transpiling, checkout the no-transpile branch of the above repo. Note that browser.js is not downloaded even though transpile is still set to "babel".

查看更多
登录 后发表回答