Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ts file and Make Its usage similar as official next-plugins #5

Merged
merged 3 commits into from
Apr 29, 2018

Conversation

lonyele
Copy link
Contributor

@lonyele lonyele commented Apr 29, 2018

Hi, I found that in a multi plugin composing case, Its usage is not same as official next-plugin thus I made these changes. If you want it as it is, still documentation is needed for its usage because It is not same as other official next-plugins)

Before

const options = {
  useCheckerPlugin: true,
  loaderOptions: {
    transpileOnly: false,
  },
};

module.exports = withAwesomeTypescript(options, withCSS({
  cssModules: true,
  cssLoaderOptions: {
    importLoaders: 1,
  }
}));

After

const awesomeTypescriptOptions = {
  useCheckerPlugin: true,
  loaderOptions: {
    transpileOnly: false,
  },
};

module.exports = withAwesomeTypescript(withCSS({
  cssModules: true,
  cssLoaderOptions: {
    importLoaders: 1,
  },
 awesomeTypescriptOptions
}));

Copy link
Owner

@saitonakamura saitonakamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really great! I was thinking about it myself, but you know how this usually works :) There's few issues to fix, but do you mind if I'll do it myself?

@@ -23,7 +23,7 @@ module.exports = (awesomeTypescriptOptions = {}, nextConfig = {}) => {
}

const { dir, defaultLoaders, dev, isServer } = options;
const { useCheckerPlugin, loaderOptions } = awesomeTypescriptOptions;
const { useCheckerPlugin, loaderOptions } = nextConfig.awesomeTypescriptOptions;
Copy link
Owner

@saitonakamura saitonakamura Apr 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if awesomeTypescriptOptions is null or undefined, I guess we can write it as const { useCheckerPlugin, loaderOptions } = nextConfig.awesomeTypescriptOptions || {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. If a user doesn't pass any arguments then my code will fail.

@@ -35,7 +35,7 @@ module.exports = (awesomeTypescriptOptions = {}, nextConfig = {}) => {

if (dev && !isServer) {
config.module.rules.push({
test: /\.tsx?$/,
test: /\.(ts|tsx)?$/,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this change, to be more aligned with next-plugins codebase? I mean I don't mind, just want to clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I had an error with myFile.ts file. I usually use .ts file If It's not a react component. I may be wrong, if there is another way to use .ts file then let me know.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, that's strange, because tsx? means ts or tsx which is exactly (ts|tsx). I'll check it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It didn't work with my code, but maybe I was doing wrong. webpack is still complicated to me...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've checked it, and tsx? is working fine on my side for .ts files. Feel free to raise an issue if the error persists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested again by making ts file and import from another file... and It worked! hm... I thought to make stateless functional component with .ts file should work and It didn't... It should have been .tsx because It looks like just an arrow function, but It has html and other tsx syntax. sorry for this stupid mistake. But If It worked from by not making stupid mistake, I wouldn't even start looking it more about this next-plugins hahaha

useCheckerPlugin: true,
loaderOptions: {
transpileOnly: false,
},
};

module.exports = withAwesomeTypescript(options);
module.exports = withAwesomeTypescript(awesomeTypescriptOptions);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be module.exports = withAwesomeTypescript({ awesomeTypescriptOptions });

```

Optionally you can add your custom Next.js configuration as second parameter
Optionally you can add your custom Next.js configuration as a parameter
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we'll merge last two cases into one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, If you want!

@lonyele
Copy link
Contributor Author

lonyele commented Apr 29, 2018

This is one of my very first PR, so If there is any problem, please let me know. Think me as a junior programmer :D Also I made a PR to next-plugins about the document. just in case. (vercel/next-plugins#156)

@saitonakamura saitonakamura merged commit f38c8aa into saitonakamura:master Apr 29, 2018
@saitonakamura
Copy link
Owner

@lonyele that's a pretty good PR, even for the first one! I fixed the issues (I hope you don't mind) and merged the branch. And, for the future, it's better to create a feature branch for each PR, it's easier to work with.

@saitonakamura
Copy link
Owner

saitonakamura commented Apr 29, 2018

Ok, I've released v0.3.0, really thanks for the PR! 👍

@lonyele
Copy link
Contributor Author

lonyele commented Apr 30, 2018

Wow! Thanks for your feedback and merging work. I would definitely make feature branch and PR next time. still, I don't know how this open source workflow works. on top of that, I use git only for myself... It is my first time sharing my code with others. anyway, thanks a lot~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants