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

Replace browserify/gulp with Webpack #5918

Merged
merged 27 commits into from
Sep 16, 2016
Merged

Replace browserify/gulp with Webpack #5918

merged 27 commits into from
Sep 16, 2016

Conversation

sminnee
Copy link
Member

@sminnee sminnee commented Aug 28, 2016

Details in the commits, feedback welcome!

Pull requests:
silverstripe/silverstripe-cms#1589
silverstripe/silverstripe-asset-admin#249
silverstripe/silverstripe-testsession#41
silverstripe/silverstripe-reports#48
silverstripe/silverstripe-simple#42

TODO

  • Docs: Fix 4.0 changelog
  • Docs: Fix https://docs.silverstripe.org/en/4.0/contributing/build_tooling/
  • Docs: Fix https://docs.silverstripe.org/en/4.0/developer_guides/customising_the_admin_interface/how_tos/extend_cms_interface/
  • Full Behat test run on CMS (with new framework branch)
  • Fix CSS includes to fix UploadField styling
  • Fix styling on show change password fields as closed by default (not referencing CSS correctly)
  • Fix UploadField upload behaviour
  • Update references to blueimp and jquery.sizes to reference node_module rather than thirdparty. Delete files from thirdparty. See https://github.com/silverstripe/silverstripe-framework/blob/master/gulpfile.js#L90 (note: TinyMCE stays in thirdparty for now)
  • Implement sprite generation (decided it's no longer required)
  • Update docs to mention sprite generation is considered deprecated
  • Document how we use webfonts (SaaS, contact us if you want to add any)
  • Test installer styling
  • Doublecheck we've covered everything and remove Gulpfile.js
  • fix cms "more options" menu popup alignment
  • Document dependencies being copied manually into thirdparty (e.g. TinyMCE) Actually just removed tinymce from NPM deps, since we're not using it (only the manual copy in thirdparty). Can be added back once we implement my suggestion in comments below.
  • Move JS-related thirdparty/ code into admin/thirdparty
  • Test multilingual CMS

Notes

  • npm run sanity has been removed, because the manual copying of libraries from src to dist is, by and large, not needed. TinyMCE is still included from framework/thirdparty

@stevie-mayhew
Copy link
Contributor

One think I notice is that it appears there isn't an explicit set to NODE_ENV=production for production builds. Will have a browse through the rest of it today.

@chillu
Copy link
Member

chillu commented Aug 29, 2016

Hey Sam, this looks awesome!

Could we either move this to the open-sausages repo, or give me temporary commit rights on your fork? I could also send pull requests to your fork, but that seems a bit overkill :)

Converted asset-admin, JS seems to work, figured it's the best way to learn. I can't get the CSS to compile. I've had to expose the new FormBuilderModal via framework. Also had to npm-shrinkwrap in framework in order to get npm install behaving. Check new commits on the open-sausages framework fork.

https://github.com/open-sausages/silverstripe-framework/tree/webpack
https://github.com/open-sausages/silverstripe-cms/tree/webpack
https://github.com/open-sausages/silverstripe-asset-admin/tree/webpack

I got a bit confused by the expose calls hidden away in bundles/lib.js, particularly since webpack.config.js has the equivalent export statements (in order to share modules within multiple bundles produced by framework). Should we move this to webpack.config.js completely? See https://github.com/webpack/expose-loader

module: {
  loaders: [
    { test: require.resolve("react"), loader: "expose?React" }
  ]
}

We have to fix the 4.0 changelog referencing build tooling as well as docs references to browserify:
https://docs.silverstripe.org/en/4.0/contributing/build_tooling/
https://docs.silverstripe.org/en/4.0/developer_guides/customising_the_admin_interface/how_tos/extend_cms_interface/

@chillu
Copy link
Member

chillu commented Aug 30, 2016

@sminnee Done some more work on this (in the open-sausages branches). Kept your commits intact to make review easier, we'll need to squash a bit once you're happy with my modifications.

I now know why you didn't use loaders for the expose config - you need scripts to be loaded in an order dependant way - all good.

Added some TODOs to the PR description.

I've done a bit of testing, looks good in IE10 and Chrome (main interactions, no missing files, no console errors). A full Behat run should uncover things pretty well

@chillu
Copy link
Member

chillu commented Aug 30, 2016

Talked to Sam and decided to push my commits to sminnee instead of the open-sausages repo. Removed the cms and framework repos, kept the asset-admin one intact. Current work:

https://github.com/sminnee/silverstripe-framework/tree/webpack
https://github.com/sminnee/silverstripe-cms/tree/webpack
https://github.com/open-sausages/silverstripe-asset-admin/tree/webpack

@@ -1,4 +1,4 @@
window.tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl(
tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could add window.tmpl like in UploadField_uploadtemplate.js for consistency, not a breaking change

@sminnee
Copy link
Member Author

sminnee commented Aug 31, 2016

@chillu I think that the partial revert of the dist rebuild is a bit excessive. Having done a search through the code for <img> tags, I see the following:

framework/admin:

  • framework/admin/client/dist/images/spinner.gif (from CMSLoadingScreen.ss)

framework:

  • BBCodeParser references images but this code is broken, so I think it's safe to ignore.

cms:

  • cms/client/dist/images/dialogs/alert.gif (from Install_successfullyinstalled.ss)

installer, asset-admin, siteconfig, reports: none

@chillu
Copy link
Member

chillu commented Sep 1, 2016

@sminnee I've pushed an update (and squashed). It's less about <img> references, most of these images are referenced in SCSS files through url(). I've gone through each image in client/dist/images and admin/client/dist/images and checked for their use, and trimmed down accordingly. Everything that's left in there is actually in use (at least until Paul gets around doing more vectorised implementations). I've removed images from dist/ which were inlined into the SCSS via data-urls.

Added a few TODOs at the top. What's your take on copying and sanity checking (diffing) third party code? Ideally we can get proper ES6 exports for those, not sure if anything has changed since we last looked at those particular libs.

@unclecheese We've talked about updating build tooling docs for SS4 on Twitter the other day. I've had to rewrite some of this in this PR as part of the Webpack switch, and restructured it a bit while I was going as well. Wanna have a read? Does the webpack.config.js setup generally make sense to you?

chillu added a commit to open-sausages/silverstripe-asset-admin that referenced this pull request Sep 1, 2016
@chillu
Copy link
Member

chillu commented Sep 1, 2016

Talked a bit more with Sam offline:

  • Remove duplication in thirdparty, reference node_modules if possible
  • Keep TinyMCE bundled through tinymce_gzip.php for now, the way plugins are configured doesn't lend itself to bundling with webpack (you have to prevent the plugin JS from being loaded to remove behaviour, there's no configuration to disable an already loaded plugin)
  • Note why we removed spriting (new stuff should be webfonts)
  • Document how we use webfonts (SaaS, contact us if you want to add any)

We've been able to remove nearly a THOUSAND FRICKEN NPM PACKAGES by switching to Webpack (and simplifying the build, e.g. no more spriting and coffeescript processing) - a full third less.

Before

npm ls | wc -l
3189
du -hc node_modules
763M    total

After

npm ls | wc -l
2301
du -hc node_modules
687M    total

@chillu
Copy link
Member

chillu commented Sep 6, 2016

Further to the point of loading TinyMCE via the PHP GZIP script: An example of procedural plugin registration, and the corresponding add() API.

If we keep a list of pre-bundled default plugins in our own bundle-lib.js, we could change HtmlEditorConfig to output a <script> tag which calls the corresponding remove() API in TinyMCE on plugins which have been removed through PHP or YAML config. New plugins added through HtmlEditorConfig would be loaded as separate JS files by default, and use the procedural add()

chillu added a commit to open-sausages/silverstripe-asset-admin that referenced this pull request Sep 7, 2016
@chillu
Copy link
Member

chillu commented Sep 9, 2016

@flamerohr added a react-based mini-pattern-lib to frameworktest via silverstripe/silverstripe-frameworktest#22. Which means we should migrate this to Webpack as well

@chillu
Copy link
Member

chillu commented Sep 12, 2016

Facebook has released a create-react-app boilerplate which comes with a default webpack.config.js - worth a look:

https://github.com/facebookincubator/create-react-app/blob/master/config/webpack.config.dev.js
https://github.com/facebookincubator/create-react-app/blob/master/config/webpack.config.prod.js

@tractorcow
Copy link
Contributor

Noted that the cms popup menu is aligned wrong. I've added a bullet to the todos.

image

@tractorcow
Copy link
Contributor

I got this error running npm run build

ERROR in ./admin/client/src/bundles/lib.js
Module not found: Error: Cannot resolve module 'blueimp-file-upload/jquery.fileupload-ui.js' in /Users/dmooyman/Sites/ss40webpack/framework/admin/client/src/bundles
 @ ./admin/client/src/bundles/lib.js 58:0-54

@tractorcow
Copy link
Contributor

For some weird reason, ontabsbeforeactivate in LeftAndMain.ActionTabSet.js isn't being triggered anymore.

@tractorcow
Copy link
Contributor

tractorcow commented Sep 13, 2016

It's caused by https://bugs.jqueryui.com/ticket/9316.

widgetEventPrefix is empty, so onbeforeactivate is triggered, but not ontabsbeforeactivate.

I think it's a bit beyond me to figure out how it's being broken... I might need to leave it to a frontender. =(

@chillu
Copy link
Member

chillu commented Sep 13, 2016

@sminnee I think we’re hitting this for Webpack’s TextExtract loader: webpack-contrib/extract-text-webpack-plugin#179 - basically it silently fails to merge multiple entry points into a single CSS file. It works with a [name] placeholder, but then you end up with bundle-legacy.css etc.

I'll comment out all the require(*.scss) statements for now, and move them all into bundle.scss as a separate entry point - then we can use [name] - it'll only create one CSS file because the other ones don't reference any SCSS

@sminnee
Copy link
Member Author

sminnee commented Sep 13, 2016

Yeah good approach to get this over the line. We can refine later if we want.

@tractorcow
Copy link
Contributor

I've had to back-port the above bugfix into our copy of jquery-ui.js, which is currently at 1.9. I attempted to upgrade to ui 1.10.4, but this would require us to re-do all our code which relied on .data() behaviour from 1.8, which is a breaking change.

@tractorcow
Copy link
Contributor

I've fixed pretty much all that I can... the only remaining issue blocking tests passing is the framework/client/src/styles/legacy not being included in the dist css files.

chillu pushed a commit to sminnee/silverstripe-cms that referenced this pull request Sep 14, 2016
chillu added a commit to open-sausages/silverstripe-asset-admin that referenced this pull request Sep 14, 2016
chillu added a commit to open-sausages/silverstripe-testsession that referenced this pull request Sep 14, 2016
When adding the deps straight into the file (recommended),
the onchange handler in file-upload isn't firing properly when a file is uploaded through
the <input type=file> button - it falls back to default behaviour, which submits the
containing form, failing because the upload is handled by a different URL.
@chillu chillu mentioned this pull request Sep 15, 2016
1 task
@chillu
Copy link
Member

chillu commented Sep 15, 2016

OMG, I think this is actually ready to merge now! Behat and PHPUnit tests are passing locally for me. There's one test failure which is due to changed paths in the "simple" theme (silverstripe/silverstripe-simple#42, InvalidArgumentException: File framework/thirdparty/jquery/jquery.js does not exist).

@sminnee sminnee closed this Sep 16, 2016
@sminnee sminnee reopened this Sep 16, 2016
@@ -106,7 +106,7 @@ public function getPreviewURL()
}

// Default media
return FRAMEWORK_DIR . '/images/default_media.png';
return FRAMEWORK_DIR . '/client/dist/images/src/default_media.png';
Copy link
Member Author

Choose a reason for hiding this comment

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

should we squash this back to "FIX Webpack handles images & fonts"?

Copy link
Member

Choose a reason for hiding this comment

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

It's a bit hard to tell which commit this belongs to, since that line has been changed in the PR afterwards - I'd say just leave it here, unless you can point out a commit

@sminnee
Copy link
Member Author

sminnee commented Sep 16, 2016

OK I've reviewed Ingo's changes to this and I'm happy, assuming the tests pass.

@@ -3,6 +3,8 @@
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't see how this file is actually getting included, and my suspicion is that the code is so edge-case that tests don't file if we remove it entire.

Can we see some evidence that the .cms-content-tools #Form_SearchForm entwine rule has been bundled?

If not, do we need to include these files in the bundle-legacy entrypoint?

Copy link
Member

Choose a reason for hiding this comment

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

Good point, I've added it to legacy.js now and verified that the "expand csv stuff" feature works in ModelAdmin (so the JS kicks in)

chillu and others added 14 commits September 16, 2016 13:44
There's not a lot of benefit in packaging these separately in terms of initial CMS load size,
so let's simplify the setup. They'll eventually become lazy loaded chunks in a React-based setup
Used in iframe, so can't be rolled into other code.
Moved in admin/ since that's easier for now with Webpack entry points,
and we'll move all JS/CSS into admin/ anyway soon.
We've removed the ability to directly reference JS and CSS files
for form fields and other SilverStripe features in favour of a common bundle built by Webpack.

The logical next step is to make the framework module free of frontend dependencies,
which should simplify its operation, and avoid another time intensive "npm install" on a module.
The JavaScript i18n functionality in SilverStripe is used in the CMS as well as form field implementations.
Form fields used to include their own JavaScript for usage outside of CMS. This now requires custom build tooling in a project.
Hence there's no need for an i18n shim (i18nx.js), since the CMS always uses i18n support.
Storing in fonts/, not font/fonts
Multiple entry points can't result in a single bundle.css with a fixed filename, see
webpack-contrib/extract-text-webpack-plugin#179

Until that's resolved, it's easier to keep the 'css' task separate in Webpack,
and have a single entry point for all CSS (bundle.scss).

Also partially reverting "Moved frontend assets into admin/ "module"",
which moved too many files: debug.css and install.css need to remain
as framework (not admin) deps. Split out into a separate `framework-css` Webpack
task in preparation for splitting off the module.
We don't have an easy way to copy over those files automatically into the thirdparty/ dir,
where they are accessible on the webroot (not the case in node_modules).

To avoid confusion, we don't duplicate into node_modules for now.
See #5918 (comment)
They were used for TreeDropdownField JavaScript tests but were never run
on CI, hence have been a bit of a wasted effort.

We're using a different JS unit testing solution now (geared towards React),
and running Jasmine in parallel on Travis for a few test cases
doesn't warrant the setup effort involved.

The TreeDropdownField component will eventually move to a React solution
which can be developed in a test-driven fashion.
The 'admin' module will be split off from 'framework',
where 'framework' only provides (mostly) frontend-agnostic PHP classes.
For example, HTMLEditorField.php has a TinyMCEConfig.php driver,
but doesn't come with its own JS includes.
When rewriting the i18n.js file from ES5 to ES6, the detectLocale()
call in the constructor was missed - meaning the lang files were loaded by the browser,
but never actually used.
We're no longer copying JS sources around,
hence there's no need for this task.
@sminnee
Copy link
Member Author

sminnee commented Sep 16, 2016

OK all tests except the CMS ones pass. @tractorcow do you want to merge this?

@tractorcow
Copy link
Contributor

I've merged cms + testsession, restarting framework build.

@sminnee
Copy link
Member Author

sminnee commented Sep 16, 2016

@tractorcow we're green. :-) I'm merging

@sminnee sminnee merged commit a1c9de3 into silverstripe:master Sep 16, 2016
sminnee pushed a commit to silverstripe/silverstripe-asset-admin that referenced this pull request Sep 16, 2016
@tractorcow tractorcow deleted the webpack branch September 16, 2016 02:33
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.

6 participants