Giter Site home page Giter Site logo

Some corner case about swc HOT 20 CLOSED

swc-project avatar swc-project commented on May 7, 2024
Some corner case

from swc.

Comments (20)

muzea avatar muzea commented on May 7, 2024 2

If just test, it doesn't seem to have much code to write a webpack loader.

const { transform } = require('swc')

module.exports = function(source) {
  const callback = this.async();
  new Promise(function() {
    callback(null, transform(source).code);
  })
};

work fine for me.

from swc.

muzea avatar muzea commented on May 7, 2024 2

@useafterfree Just a simple demo
https://github.com/muzea-demo/swc-loader
use yarn link or npm link
https://github.com/muzea-demo/swc-loader-demo
Then install swc-loader in this project, run make.js to generate the lodash entry file.

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 1

Thank you very much for trying swc.
The es3::reserved_word pass is not implemented yet, so I guess it's expected result.
I'll fix it after finishing jsx support.

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 1

Fixed in version 0.1.0

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 1

@muzea I implemented commonjs / umd module bundler.
You can use like

{
  "module": {
    "type": "commonjs"
  }
}

See: https://swc-project.github.io/docs/configuring-swc#module

from swc.

muzea avatar muzea commented on May 7, 2024 1

@kdy1 Awesome.
Will swc add some real-world tests like v8?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 1

@muzea Definitely yes.
Note that currently swc already passes almost all tests copied from babel

from swc.

useafterfree avatar useafterfree commented on May 7, 2024

@muzea How did you compile lodash with swc? Can you post an example?

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 Now I can run through the demo, very exciting work.
But the results here are very strange.
If entry file is ./src/lodash.js, only the meaningless assignments are included in the packaged results, and there are a lot of blank lines inside.
If entry file is ./src/test.js, result is

WARNING in ./src/test.js 2:12-18
"export 'default' (imported as 'lodash') was not found in './lodash'

It’s convenient to see why it is?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

I guess ./src/test.js resulted in error because es module transform is not implemented yet.

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 Corresponding to babel, is it babel-plugin-transform-modules-commonjs?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

@muzea You are correct. I'll implement it soon.

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

I could compile whole lodash with swc-cli. Is it okay to close the issue?

I used npx swc -d out *.js

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 Transform a single file is no error, but I want to use it with webpack.

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 swc-cli seems to be a bit problematic(0.0.3), the lib directory after the bundle is not in the npm package.

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 nice, cli now work fine. Is there a configuration description of the transform?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

Currently it is documented only on index.d.ts
I'll add it to docs soon

See: https://swc-project.github.io/docs/configuring-swc#jsctransform

from swc.

muzea avatar muzea commented on May 7, 2024

@kdy1 I see this example. If I want to transform to cjs or es3, how do I configure it?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

Currently it's not possible. I will implement module passes soon

from swc.

swc-bot avatar swc-bot commented on May 7, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

from swc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.