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

Webpack + Jest #12

Merged
merged 21 commits into from
Aug 9, 2017
Merged

Webpack + Jest #12

merged 21 commits into from
Aug 9, 2017

Conversation

fernandosouza
Copy link
Contributor

@fernandosouza fernandosouza commented Jul 20, 2017

Hey, guys. Based on what Chema did for Clay Components, I've replaced Gulp to Webpack and Karma to Jest.

Please, give me feedbacks.

@fernandosouza fernandosouza changed the title Adds lock file Webpack + Jest Jul 20, 2017
@jbalsas
Copy link

jbalsas commented Jul 26, 2017

Hey @fernandosouza, thanks a lot for putting this together! I'll take a look tomorrow!

@fernandosouza
Copy link
Contributor Author

Thx, @jbalsas.

Copy link

@jbalsas jbalsas left a comment

Choose a reason for hiding this comment

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

Hey @fernandosouza, this looks quite good, I've just added some comments from a quick review.

Also, could we move to an .eslintrc similar to https://github.com/metal/metal-clay-components/blob/master/.eslintrc ? That would conform to our more current standards

}
);
this.fs.copyTpl(
this.templatePath('test/_Boilerplate.js'), this.destinationPath('test/' + this.componentName + '.js'),
this.templatePath('__tests__/_Boilerplate.js'), this.destinationPath('__tests__/' + this.componentName + '.js'),
Copy link

Choose a reason for hiding this comment

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

Should this depend on the chosen testEnvironment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly. It's just a configuration option for Karma. I thought to keep the same folder name to avoid the condition of the test environment. This name is the default for Jest and for Karma we always have to specify the test folder. So, made more sense for me to use __tests__. Does it make sense?

Copy link

Choose a reason for hiding this comment

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

mmm... it makes sense for us as maintainers, but I doubt that if you pick Karma as a test environment you expect tests to be there...

filename: './build/<%= buildFormat %>/<%= kebabCaseName %>.js'<% } %>
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin()
Copy link

Choose a reason for hiding this comment

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

Based on metal/metal.js#251, maybe we'd like to add the commonsChunk plugin by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chunk means separate in another file what is common for components in a bundle. Right?

Copy link

@robframpton robframpton Jul 27, 2017

Choose a reason for hiding this comment

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

Isn't the commonChunk plugin only useful for builds that have multiple entry points? I think webpack 3 already attempts to dedupe as much as possible (given that you don't even need to include the plugin anymore https://webpack.js.org/guides/migrating/#dedupeplugin-has-been-removed).

Copy link

Choose a reason for hiding this comment

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

Yeah, I was just pointing that if someone tries to create entry points based on this generator the duplicated IncrementalDOM dependency will trip her up as seen in the referenced metal.js issue. This is might be a big gotcha, so we can either set it as default, or simply document it somewhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if we add the resolve alias in the generator? The highest component will resolve dependencies correctly. With the documentation you've suggested, @jbalsas, developers who didn't use the generator will be able to a fix his setup.

@jbalsas
Copy link

jbalsas commented Jul 27, 2017

@mthadley, @bryceosterhaus do you guys have any suggestions for the generator setup? Some things you'd like to see? Maybe we could add a jsx flavour as well (in a different issue 😁)...

@Robert-Frampton, @brunobasto, thoughts on this?

@robframpton
Copy link

Hey @fernandosouza

I tried running this with all the default options, and npm choked on the generated package.json file.

screen shot 2017-07-27 at 8 39 01 am

import Component from 'metal-component';<% } %><% if (buildFormat === 'jquery') { %>
import JQueryAdapter from 'metal-jquery-adapter';<% } %>

import './<%= kebabCaseName %>.scss';

Choose a reason for hiding this comment

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

I'm a little worried about importing the scss by default, since it constricts the bundling process quite a bit. What if someone else wanted to use this component but didn't want to webpack their styles? Just a thought, I'm open to discussion.

@jbalsas , what do you think?

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'm not sure if there is a way to deal with scss with Webpack in another way. Webpack receives a Javascript entry file and handles everything from that. There is a plugin that we can use to extract the CSS part from the bundle to another file.

@fernandosouza
Copy link
Contributor Author

@Robert-Frampton. I sent a new commit that seems to fix the error.

@bryceosterhaus
Copy link
Member

@jbalsas nothing in particular stands out to me. I haven't used this generator yet and usually don't use generators at all, so I don't have much input for this specific use case.

Glad to see Jest and Webpack being added though, I think it will help first-timers.

@brunobasto
Copy link

Hey @fernandosouza, I'm afraid we shouldn't change the package name. Is there any particular reason you did so?

@robframpton robframpton merged commit 3c9506d into metal:master Aug 9, 2017
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.

5 participants