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

Scripts: Add support for start and build scripts to the package #12837

Merged
merged 5 commits into from
Jan 23, 2019

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Dec 13, 2018

Description

Inspired by work done by @griffbrad in #12685 where he tries to extract the big chunk of Webpack config for the usage outside of Gutenberg. This PR offers two new @wordpress/scripts commands to help with maintaining ESNext codebase:

  • wp-scripts build
  • wp-scripts start

This PR doesn't provide the default Webpack config. I'm leaving it for #12685.

It uses Parcel by default to make it easy to start using build tools for plugin developers. It should work for plugins without any Babel config provided. However, it would be nice to recommend using @wordpress/babel-preset-default to get everything aligned with core development.
Edit: I removed Parcel integration from this PR as it can't be zero-config for WordPress development because of the need to provide Babel config override manually. Parcel also doesn't allow to list the packages which won't be bundled - we need that for all WordPress packages that are being already served by WordPress core.

For advanced usage it uses Webpack when accompanying config file is provided using on of the following:

  • --config CLI option
  • webpack.config.js
  • webpack.config.babel.js

This PR is still in progress. It needs the following: Tasks finished:

  • documentation in @wordpress/scripts package
  • changelog for @wordpress/scripts to be updated

How has this been tested?

  • npm run dev
  • ./node_modules/.bin/wp-scripts start
  • npm run build
  • ./node_modules/.bin/wp-scripts build

@gziolo gziolo added [Status] In Progress Tracking issues with work in progress [Type] Build Tooling Issues or PRs related to build tooling [Package] Scripts /packages/scripts labels Dec 13, 2018
@gziolo gziolo self-assigned this Dec 13, 2018
@gziolo gziolo force-pushed the add/scripts-build-start branch 2 times, most recently from 3a3c365 to 34649e5 Compare January 15, 2019 15:58
@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Jan 15, 2019
@gziolo gziolo requested review from ntwb and nerrad January 15, 2019 18:35
packages/scripts/README.md Outdated Show resolved Hide resolved
packages/scripts/scripts/build.js Outdated Show resolved Hide resolved
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

👍 to the changes. Still have a minor question though.

packages/scripts/scripts/build.js Outdated Show resolved Hide resolved
@gziolo gziolo added this to the 5.0 (Gutenberg) milestone Jan 21, 2019
@gziolo
Copy link
Member Author

gziolo commented Jan 21, 2019

@youknowriad are we fine to land it as part of 5.0 (Gutenberg)?

@youknowriad
Copy link
Contributor

I'm personally fine, but would love some inputs from people that tried building custom plugins and if this solves their need cc @aduth ?

@gziolo gziolo requested review from ellatrix and mkaz January 21, 2019 17:38
@gziolo
Copy link
Member Author

gziolo commented Jan 21, 2019

I'm personally fine, but would love some inputs from people that tried building custom plugins and if this solves their need cc @aduth ?

Adding @iseulde and @mkaz to the list of reviewers as they might also have some experience with building plugins.

@aduth
Copy link
Member

aduth commented Jan 22, 2019

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks good 👍 Becomes most useful with the default configuration.


if ( hasWebpackConfig ) {
// Sets environment to production.
process.env.NODE_ENV = 'production';
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 strange to me for the script to be explicitly assigning an environment variable, though I think it's likely the most effective way to capture how most configurations would consider the current environment.

https://webpack.js.org/guides/production/#specify-the-mode

Copy link
Member Author

Choose a reason for hiding this comment

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

It replicates what Gutenberg does as of today. There is a similar trick used for unit tests where NODE_ENV is forced to test.

@gziolo gziolo merged commit 6c4a1d1 into master Jan 23, 2019
@gziolo gziolo deleted the add/scripts-build-start branch January 23, 2019 08:22
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Scripts: Add build and start scripts to wp-script

* Introduce start and build scripts in scripts package

* Use Webpack for builds in scripts package

* Add documentation for start and build commands

* Address feedback from review
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Scripts: Add build and start scripts to wp-script

* Introduce start and build scripts in scripts package

* Use Webpack for builds in scripts package

* Add documentation for start and build commands

* Address feedback from review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Scripts /packages/scripts [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants