Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ docs/

# Ignore third-party code
src/vendor

# The test folder uses ES modules
test/src
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
package-lock.json
test/build
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
script: "npm run lint && npm run test"
script: "npm run lint && npm run test && npm run test-build"
node_js:
- node
- lts/*
Expand Down
4 changes: 3 additions & 1 deletion docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ npm install --save-dev @humanmade/webpack-helpers
While this package depends in turn on a number of loaders and plugins, it deliberately does _not_ include `webpack` itself. To install this library along with all its relevant peer dependencies, therefore, you may run the following command:

```bash
npm install --save-dev @humanmade/webpack-helpers webpack webpack-cli webpack-dev-server node-sass
npm install --save-dev @humanmade/webpack-helpers webpack@4 webpack-cli webpack-dev-server sass
```

Note that we specify Webpack version 4. Support for Webpack 5 is anticipated in the v1.0 release of these helpers, but at present using Webpack 4 provides the most predictable and stable experience across our projects.

## Configuring Webpack

By convention we generally put our Webpack configuration in a `.config/` folder in the project root. If you're working on a specific theme or plugin the project root may be the theme or plugin folder root, but on an Altis or WordPress VIP project the project root is likely to be the `wp-content` root or a folder outside your web root entirely. By putting your Webpack configuration at this higher level, one Webpack build command or dev server instance may be used to bundle the assets for multiple relates themes and plugins.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"scripts": {
"lint": "eslint .",
"test": "jest"
"test": "jest",
"test-build": "webpack --config=test/test-config.js"
},
"jest": {
"setupFilesAfterEnv": [
Expand All @@ -32,6 +33,7 @@
"sass": "^1.26.10",
"typescript": "^4.0.2",
"webpack": "^4.35.0",
"webpack-cli": "^4.3.1",
"webpack-dev-server": "^3.7.2"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions test/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require( '../babel-preset' );
6 changes: 6 additions & 0 deletions test/src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const wait = ( delay ) => new Promise( ( resolve ) => setTimeout( resolve, delay ) );

export const getResults = async () => {
await wait( 500 );
return 'Results';
};
8 changes: 8 additions & 0 deletions test/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getResults } from './helpers';

import './style.scss';

( async () => {
const results = await getResults();
console.log( results );
} )();
11 changes: 11 additions & 0 deletions test/src/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
div {
p {
font-family: 'Papyrus';

&:first-child {
color: 'red';
font-weight: bold;
font-family: 'Comic Sans MS', sans-serif;
}
}
}
24 changes: 24 additions & 0 deletions test/test-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { presets, helpers } = require( '../index' );

const { filePath } = helpers;

module.exports = [
presets.production( {
name: 'production-test',
entry: {
prod: filePath( 'test/src/index.js' ),
},
output: {
path: filePath( 'test/build/prod' ),
}
} ),
presets.development( {
name: 'dev-test',
entry: {
prod: filePath( 'test/src/index.js' ),
},
output: {
path: filePath( 'test/build/dev' ),
},
} ),
];