Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Better default webpack config #1212

Closed
wants to merge 9 commits into from

Conversation

drazik
Copy link
Contributor

@drazik drazik commented Dec 5, 2017

Related to #1210. It is currently a not tested WIP. I just want to get some feedback from @MoOx for the moment. Does it match to what you imagined ?

Here are some random things :

  • To filter the rules, I used the loader property, not test as you suggested to me, because some of the tests are arrays, so I felt it was more difficult to use it in conditions
  • I think some plugins used in react-scripts are not necessary in phenomic : InterpolateHtmlPlugin, HtmlWebpackPlugin, DefinePlugin... Do we keep them anyway ?

Copy link
Owner

@MoOx MoOx left a comment

Choose a reason for hiding this comment

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

Looking good so far! I like it!

@@ -33,6 +33,7 @@
"find-cache-dir": "^0.1.1",
"multili": "^1.1.0",
"react-hot-loader": "^3.0.0-beta.7",
"react-scripts": "1.0.17",
Copy link
Owner

Choose a reason for hiding this comment

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

Please use "^1.0.17"

@@ -3,22 +3,27 @@ import path from "path";
import webpack from "webpack";
import ExtractTextPlugin from "extract-text-webpack-plugin";

const isStatic = process.env.PHENOMIC_ENV === "static";
const isProduction = process.env.NODE_ENV === "production";
Copy link
Owner

Choose a reason for hiding this comment

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

You cannot put this statically. Must be in the fonction to be safe (since we can adjust this during a function - we are not 100% sure that this file won't be imported (& so evaluated) before the code that will adjust this on runtime - FYI here and here)

const isStatic = process.env.PHENOMIC_ENV === "static";
const isProduction = process.env.NODE_ENV === "production";

const baseConfig = require("react-scripts/config/webpack.config." +
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above, should be in the function.

@MoOx MoOx changed the title [WIP] Better default webpack config Better default webpack config Dec 6, 2017
@MoOx
Copy link
Owner

MoOx commented Dec 6, 2017

About the unnecessary plugins, no big deal imo, we can improve that later. I think we should only remove what's really a problem. I would like to stick to CRA default as close as possible so people can just "drop" some existing code. Removing some plugin might make sense but I prefer to not do it unless necessary.

@MoOx
Copy link
Owner

MoOx commented Dec 6, 2017

Any reason we have to maintain a specific css loader block? Is this because of the hmr?

@drazik
Copy link
Contributor Author

drazik commented Dec 6, 2017

@MoOx I did the changes you requested.

I had an error because the template for HtmlWebpackPlugin didn't exist. We don't need to use it in Phenomic, so I deleted the plugin

After that, I saw that the css was written in dist/static/css. It was because CRA config declares a cssFilename that is used in extractTextPluginOptions variable to set the publicPath in the loader. I added output.publicPath in our config, but I had to copy/paste the loader configuration without it.

I also had to put a weird computed property with a ternary condition in the CSS loader because CRA is using use in dev config and loader in prod config.

Last thing, since we have to override the ExtractTextPlugin used by CRA, and they use it only in prod, I prefered to delete it in every case and just add a new one with our own config.

I just tested with npm start and npm run build. The config does a good job on my blog.

EDIT : oops I didn't see your last comment. Actually it is because the config object is inside a ExtractTextPlugin.extract call, and we need to override this config. But I can't override it before it is processed by ExtractTextPlugin.extract, obviously. So I had to copy/paste the config and update small parts to make it fit our needs (HMR and publicPath)

@MoOx
Copy link
Owner

MoOx commented Dec 6, 2017

html plugin is supposed to be around https://github.com/facebookincubator/create-react-app/blob/4b55193f0ad479f26b0f5e153bb4b152a1ee03e7/packages/react-scripts/package.json#L45

Anyway, thanks for this, I will have a deeper look on some stuff before merging to try to reduce the maintenance even further. Thanks a lot for the work done. Stay tuned !

@MoOx
Copy link
Owner

MoOx commented Dec 6, 2017

Could you fix the yarn lock issue? Rebase on master and just do "yarn", yarn will handle the conflict (it's a yarn feature!) then you can amend your commit :)
Are you interested to be added as a collaborator on the project so you can later directly work on branches?

@drazik
Copy link
Contributor Author

drazik commented Dec 6, 2017

Yes the plugin is in the dependencies, but there is no HTML template file, so it crashed when it was trying to read it (CRA declares an index.html). Since we have nothing to do with such a file, I thought it was better to simply delete the plugin.

I will look the yarn lock issue tomorrow. And yeah, it would be so great to be added as a collaborator, thank you !

@MoOx
Copy link
Owner

MoOx commented Dec 18, 2017

@drazik any luck with yarn lock conflict? (sorry I think that's the second time??)

@bloodyowl
Copy link
Contributor

@MoOx tkt je vais m'en occuper

@MoOx
Copy link
Owner

MoOx commented Dec 18, 2017

I can still do it (merge in another branch, resolve & the merge into master). What I expect from you is more a code review what thoughts about the approach :)

Copy link
Contributor

@bloodyowl bloodyowl left a comment

Choose a reason for hiding this comment

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

the fact that its a bit too much react centric is kind of annoying I think, where should we branch? every renderer adding their options given the bundler or the other way around?

const isStatic = process.env.PHENOMIC_ENV === "static";
const isProduction = process.env.NODE_ENV === "production";

const baseConfig = require("react-scripts/config/webpack.config." +
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit worried to rely on a react repo for the webpack config (they are not coupled in Phenomic)

entry: {
[config.bundleName]: [
!isStatic && require.resolve("webpack-hot-middleware/client"),
!isStatic && require.resolve("react-hot-loader/patch"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd only add this if the React plugin is used

@MoOx
Copy link
Owner

MoOx commented Dec 18, 2017

Totally agree. I was more like "until we have other renderer we could do this and fix later".
The correct approach would me more like that any plugin could send option to any other plugins (each plugins can accept options (in theory), we could add an api or something so plugin-renderer-react could pass a config to plugin-bundler-webpack somehow...

@drazik
Copy link
Contributor Author

drazik commented Dec 19, 2017

I fixed the conflict in yarn.lock

@MoOx
Copy link
Owner

MoOx commented Dec 20, 2017

It seems that tests are failing on Windows (see appveyor state). Can you take a look?

@drazik
Copy link
Contributor Author

drazik commented Jan 2, 2018

Yes I will take a look. I'm pretty busy at the moment but I will take 10 minutes to do it this week ;)

Edit :

The error is :

ModuleParseError: Module parse failed: C:\projects\phenomic\examples\react-app-getting-started\App.js Unexpected token (14:2)
You may need an appropriate loader to handle this file type.

It seems the babel-loader is not used. But I can't see why it's the case only on Windows. Since I only have a machine with Fedora, I can't really test things directly. Do you see what can go wrong ?

@MoOx
Copy link
Owner

MoOx commented Jan 22, 2018

@drazik would you like me to continue the effort here?

@drazik
Copy link
Contributor Author

drazik commented Jan 23, 2018

Yes sorry I am very busy these days, and I don't know where the error on Windows come from. If you have time to investigate it's great :)

@MoOx
Copy link
Owner

MoOx commented Mar 15, 2018

I will try to use another approach soon. @drazik thanks a lot for digging into this, that helped me to think about a better way to integrate CRA config!

@MoOx MoOx closed this Mar 15, 2018
@drazik
Copy link
Contributor Author

drazik commented Mar 16, 2018

That's fine :) In the meantime, do you have some advices to deal with things the current webpack things doesn't handle ? I have some fonts to load, for example.

drazik added a commit to drazik/blog that referenced this pull request Mar 16, 2018
drazik added a commit to drazik/blog that referenced this pull request Mar 16, 2018
drazik added a commit to drazik/blog that referenced this pull request Mar 16, 2018
BREAKING CHANGE

* move old content in a folder

* add articles

* use phenomic with basic components

* add gitignore

* manage external posts

* max 80 chars

* outdated message

* delete twitter share link

* Delete PostsList page to show all posts on home

* use named exports only

* code highlight

* set language on all code samples

* add error page

* move posts images to public folder

* add progress bar loading

* handle fonts

* chore: update dependencies

* feat: disable custom fonts until I find how to deal with phenomic and custom webpack conf

see MoOx/phenomic#1212

* feat: update header with new job

* feat: add emoji on external links

* content: add preact discover post

* chore: delete travis deploy script
@MoOx
Copy link
Owner

MoOx commented Mar 26, 2018

You can create your own custom config. Eg: https://github.com/MoOx/maxim-hylian.fr/blob/master/webpack.config.js

@drazik
Copy link
Contributor Author

drazik commented Mar 27, 2018

Thank you 👍

@drazik drazik deleted the improve-webpack-config branch March 3, 2019 22:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants