Skip to content

Commit

Permalink
Add config variables for dev host, path, and output path
Browse files Browse the repository at this point in the history
  • Loading branch information
zackify committed May 22, 2018
1 parent d17b49f commit 023bb8a
Show file tree
Hide file tree
Showing 5 changed files with 1,343 additions and 1,330 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ Add a `gutenblock.config.js` file in your blocks folder. It looks like this:
const path = require('path');

module.exports = webpack => ({
//customize gutenblock options if needed
gutenblock: {
devHost: 'localhost',
devPort: 8080,
//build asset output path relative to the plugin directory
outputPath: '/test',
//when building the plugin, gutenblock will default to the folder name inside wp-content, if you have a different wp-content folder you can change it here
publicPath: `/app/plugins/blocks/test/`,
},
resolve: {
alias: {
shared: path.resolve(__dirname, '../src/shared'),
Expand Down
5 changes: 2 additions & 3 deletions cli/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ module.exports = () => {
console.log('Building...');

webpack(customConfig, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err);
}
if (err) console.error(err);

console.log('Done!');
});
};
11 changes: 8 additions & 3 deletions config/base.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = ({
delete customConfig.babelOptions;
}

let gutenblock = customConfig.gutenblock;
delete customConfig.gutenblock;
port = gutenblock.devPort || port;

//merge custom rules
let module = {
rules: [
Expand Down Expand Up @@ -63,14 +67,15 @@ module.exports = ({
output: {
chunkFilename: '[name].chunk.js',
filename: '[name].js',
path: process.cwd() + '/build',
path: process.cwd() + (gutenblock.outputPath || '/build'),
publicPath: production
? `/wp-content/plugins/${pluginFolderName}/build/`
? gutenblock.publicPath ||
`/wp-content/plugins/${pluginFolderName}/build/`
: `http://localhost:${port}/`,
},
serve: {
port,
host: '0.0.0.0',
host: gutenblock.devHost || '0.0.0.0',
add: (app, middleware) => {
app.use((ctx, next) => {
ctx.set('Access-Control-Allow-Origin', '*');
Expand Down
Loading

0 comments on commit 023bb8a

Please sign in to comment.