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

Plugin: Adding a build process #282

Merged
merged 5 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugin/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
[ "latest", {
"es2015": {
"modules": false
}
} ]
]
}
16 changes: 16 additions & 0 deletions plugin/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
16 changes: 16 additions & 0 deletions plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"root": true,
"extends": "wpcalypso",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 3
Copy link
Member

Choose a reason for hiding this comment

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

Likely ignored with babel-eslint parser override. Do we need to use babel-eslint or is the default parser sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the docs:

You only need to use babel-eslint if you are using types (Flow) or experimental features not supported in ESLint itself yet

We may need it, if we decide to add object-spread, but we could drop it for now.

},
"rules": {
"no-var": "off",
"camelcase": "off"
}
}
7 changes: 7 additions & 0 deletions plugin/build/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function gutenberg_menu() {

function gutenberg_scripts_and_styles( $hook ) {
if ( $hook === 'toplevel_page_gutenberg' ) {
wp_enqueue_style( 'gutenberg_css', plugins_url( 'style.css', __FILE__ ) );
Copy link
Member

Choose a reason for hiding this comment

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

Curious if extract-text-webpack-plugin (what we'd eventually want to use to pull out CSS) can be integrated easily into a development configuration.

wp_enqueue_script( 'gutenberg_js', plugins_url( 'build/app.js', __FILE__ ) );
Copy link
Member

Choose a reason for hiding this comment

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

This 404's because it's loading from the Gutenberg root. Should be plugin/build/app.js.

}
}
add_action( 'admin_enqueue_scripts', 'gutenberg_scripts_and_styles' );
Expand Down
36 changes: 36 additions & 0 deletions plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "gutenberg",
"version": "1.0.0",
"description": "Prototyping a new WordPress editor experience",
"main": "build/app.js",
"repository": "git+https://github.com/WordPress/gutenberg.git",
"author": "The WordPress Contributors",
"license": "GPL-2.0+",
"keywords": [
"WordPress",
"editor",
"prototype"
Copy link
Member

Choose a reason for hiding this comment

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

Not a prototype 😄

],
"scripts": {
"build": "cross-env NODE_ENV=production webpack",
"clean": "rimraf build"
},
"devDependencies": {
"autoprefixer": "^6.7.7",
"babel-core": "^6.24.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.4.1",
"babel-preset-latest": "^6.24.0",
"cross-env": "^3.2.4",
"css-loader": "^0.27.3",
"eslint": "^3.17.1",
"eslint-config-wpcalypso": "^0.6.0",
"eslint-plugin-wpcalypso": "^3.0.2",
"node-sass": "^4.5.0",
"postcss-loader": "^1.3.3",
"rimraf": "^2.6.1",
"sass-loader": "^6.0.3",
"style-loader": "^0.14.1",
"webpack": "^2.2.1"
}
}
13 changes: 13 additions & 0 deletions plugin/src/assets/stylesheets/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.gutenberg {
background: #fff;
margin: -20px 0 0 -20px;
padding: 60px;
}

.gutenberg__editor {
max-width: 700px;
margin: 0 auto;
img {
max-width: 100%;
}
}
6 changes: 6 additions & 0 deletions plugin/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Internal dependencies
*/
import 'assets/stylesheets/main.scss';

console.log( 'Welcome to gutenberg' ); // eslint-disable-line no-console
13 changes: 0 additions & 13 deletions plugin/style.css
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
.gutenberg {
background: #fff;
margin: -20px 0 0 -20px;
padding: 60px;
}

.gutenberg__editor {
max-width: 700px;
margin: 0 auto;
}

.gutenberg__editor img {
max-width: 100%;
}
55 changes: 55 additions & 0 deletions plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* External dependencies
*/

const webpack = require( 'webpack' );

const config = module.exports = {
entry: {
app: './src/index.js'
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking we should call this folder editor, and it would more closely represent what we may be bringing into core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about the distinction src/build? Do you think we should use editor as a parent directory or it's ok to keep build as is?

Copy link
Member

Choose a reason for hiding this comment

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

I may put the build in the root of the plugin.

},
output: {
filename: 'build/[name].js',
path: __dirname
},
resolve: {
modules: [
'src',
'node_modules'
]
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader'
},
{
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' }
]
}
]
},
plugins: [
new webpack.LoaderOptionsPlugin( {
minimize: process.env.NODE_ENV === 'production',
debug: process.env.NODE_ENV !== 'production',
options: {
postcss: [
require( 'autoprefixer' )
]
}
} )
]
};

if ( 'production' === process.env.NODE_ENV ) {
config.plugins.push( new webpack.optimize.UglifyJsPlugin() );
} else {
config.devtool = 'source-map';
}
Loading