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 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
"read-pkg-up": "^1.0.1",
"resolve-bin": "^0.4.0"
"resolve-bin": "^0.4.0",
"webpack": "4.8.3",

This comment has been minimized.

@gziolo

gziolo Dec 13, 2018

Author Member

As usual, I don't want to bump the version when doing refactoring to avoid dealing with incompatible changes.

@gziolo gziolo force-pushed the add/scripts-build-start branch 2 times, most recently from 3a3c365 to 34649e5 Jan 10, 2019

@gziolo gziolo requested review from ntwb and nerrad Jan 15, 2019

Show resolved Hide resolved packages/scripts/README.md Outdated
Show resolved Hide resolved packages/scripts/scripts/build.js Outdated

@gziolo gziolo force-pushed the add/scripts-build-start branch from 6832676 to 9d8e17b Jan 16, 2019

@gziolo gziolo requested a review from swissspidy Jan 16, 2019

@nerrad
Copy link
Contributor

nerrad left a comment

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

Show resolved Hide resolved packages/scripts/scripts/build.js Outdated

@gziolo gziolo force-pushed the add/scripts-build-start branch from 9d8e17b to c6f06ea Jan 16, 2019

@gziolo gziolo force-pushed the add/scripts-build-start branch from c6f06ea to dbeed60 Jan 21, 2019

@gziolo gziolo added this to the 5.0 (Gutenberg) milestone Jan 21, 2019

@gziolo

This comment has been minimized.

Copy link
Member Author

gziolo commented Jan 21, 2019

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

@youknowriad

This comment has been minimized.

Copy link
Contributor

youknowriad 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 ?

@gziolo gziolo requested review from iseulde and mkaz Jan 21, 2019

@gziolo

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

aduth commented Jan 22, 2019

@aduth

aduth approved these changes Jan 22, 2019

Copy link
Member

aduth left a comment

Looks good 👍 Becomes most useful with the default configuration.


if ( hasWebpackConfig ) {
// Sets environment to production.
process.env.NODE_ENV = 'production';

This comment has been minimized.

@aduth

aduth Jan 22, 2019

Member

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

This comment has been minimized.

@gziolo

gziolo Jan 23, 2019

Author Member

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@gziolo gziolo deleted the add/scripts-build-start branch Jan 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment