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

Add Preact preset (with preact-compat support) #144

Merged
merged 2 commits into from
Sep 13, 2017

Conversation

Lyrkan
Copy link
Collaborator

@Lyrkan Lyrkan commented Aug 21, 2017

This PR adds a enablePreactPreset() method to the public API.

Basically it allows to use Preact (which is an alternative to react), optionally in conjunction with preact-compat (which makes it possible to use the same code you would have in a React app).

It doesn't enable a babel preset per-se but it's still some kind of preset and it makes it consistent with the already existing enableReactPreset() method.

The method takes as an argument an option object that allows to enable/disable the use of preact-compat:

// Without preact-compat (default)
// - Adds transform-react-jsx to the plugins used by babel
//   and configures it to wrap JSX into Preact h() calls
Encore.enablePreactPreset()

// With preact-compat
// - Adds transform-react-jsx to the plugins used by babel
//   but with its default configuration (that uses React.createElement)
// - Aliases react and react-dom to use preact-compat instead
Encore.enablePreactPreset({ preactCompat: true })

I also created the following project as a PoC and it seems to be working as intended:

index.js Outdated
* @param {boolean} usePreactCompat
* @returns {exports}
*/
enablePreactPreset(usePreactCompat = false) {
Copy link
Member

Choose a reason for hiding this comment

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

This is the only part I'm not sure about. When I saw your code examples, I assumed the true/false was turning the entire feature on/off (like some of our other enable() methods). It's more verbose, but I'd prefer enablePreactPreset({preactCompat: true}) style (with our normal validating of any options passed).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I definitely agree with you :)

@weaverryan
Copy link
Member

Great work! Another excellent addition! :)

@Lyrkan Lyrkan deleted the add-preact-preset branch September 13, 2017 22:12
weaverryan added a commit that referenced this pull request Sep 14, 2017
This PR was squashed before being merged into the master branch (closes #152).

Discussion
----------

Add various methods to configure default plugins

This PR adds some methods to configure default plugins (closes #148, closes #87 and closes #15):

* `Encore.configureDefinePlugin(callback)`
* `Encore.configureExtractTextPlugin(callback)`
* `Encore.configureFriendlyErrorsPlugin(callback)`
* `Encore.configureLoaderOptionsPlugin(callback)`
* `Encore.configureUglifyJsPlugin(callback)`

Other changes:

* Allows the `clean-webpack-plugin` to be configured using `Encore.cleanupOutputBeforeBuild(paths, callback)`
* Fixed a small mistake in the `Encore.configureManifestPlugin()` jsdoc
* Reorganized flags/callbacks in the constructor of `webpack.config.js` since it was starting to be a bit hard to read. I'm not sure about the way I splitted things though, let me know what you think about it.
* Renamed `common-chunks.js` to `commons-chunks.js` since the name of the plugin is `CommonsChunkPlugin`

@weaverryan: Not directly related but while doing all of that I noticed that `sassOptions` uses snake-case whereas I used camel-case in #144 for `enablePreactPreset()` and in #115 for `configureRuntimeEnvironment()`, should we do something about that?

***Edit 1:** Added `Encore.configureCleanWebpackPlugin()`*
***Edit 2:** Removed `Encore.configureCleanWebpackPlugin()` to use `Encore.cleanupOutputBeforeBuild(paths, callback)` arguments instead*

Commits
-------

286787a Minor text changes
f72614b Remove configureCleanWebpackPlugin and use cleanupOutputBeforeBuild arguments instead
90c8565 Add various methods to configure default plugins
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.

2 participants