| 1 |
// WordPress webpack config. |
| 2 |
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); |
| 3 |
|
| 4 |
// Plugins. |
| 5 |
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' ); |
| 6 |
const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); |
| 7 |
|
| 8 |
// Utilities. |
| 9 |
const path = require( 'path' ); |
| 10 |
const imagesPath = path.resolve( __dirname, './build/images' ); |
| 11 |
|
| 12 |
const modulesDir = process.cwd() + '/modules/'; |
| 13 |
|
| 14 |
const entryPoints = { |
| 15 |
// Admin module: |
| 16 |
'js/helloplus-onboarding': path.resolve( modulesDir, 'admin/assets/js', 'hello-plus-onboarding.js' ), |
| 17 |
'js/helloplus-whats-new': path.resolve( modulesDir, 'admin/assets/js', 'hello-plus-whats-new.js' ), |
| 18 |
|
| 19 |
// Content module |
| 20 |
'css/helloplus-zigzag': path.resolve( modulesDir, 'content/assets/scss', 'hello-plus-zigzag.scss' ), |
| 21 |
'css/helloplus-hero': path.resolve( modulesDir, 'content/assets/scss', 'hello-plus-hero.scss' ), |
| 22 |
'css/helloplus-cta': path.resolve( modulesDir, 'content/assets/scss', 'hello-plus-cta.scss' ), |
| 23 |
'css/helloplus-flex-hero': path.resolve( modulesDir, 'content/assets/scss', 'hello-plus-flex-hero.scss' ), |
| 24 |
'css/helloplus-contact': path.resolve( modulesDir, 'content/assets/scss', 'hello-plus-contact.scss' ), |
| 25 |
'js/helloplus-zigzag-fe': path.resolve( modulesDir, 'content/assets/js/frontend', 'hello-plus-zigzag-fe.js' ), |
| 26 |
'css/helloplus-control-choose-img': path.resolve( modulesDir, 'content/assets/scss', 'choose-img.scss' ), |
| 27 |
'js/helloplus-control-choose-img': path.resolve( modulesDir, 'content/assets/js', 'editor.js' ), |
| 28 |
|
| 29 |
// Template Parts module |
| 30 |
'css/helloplus-template-parts-editor': path.resolve( modulesDir, 'template-parts/assets/scss', 'editor.scss' ), |
| 31 |
'css/helloplus-header': path.resolve( modulesDir, 'template-parts/assets/scss', 'hello-plus-header.scss' ), |
| 32 |
'css/helloplus-footer': path.resolve( modulesDir, 'template-parts/assets/scss', 'hello-plus-footer.scss' ), |
| 33 |
'js/helloplus-header-fe': path.resolve( modulesDir, 'template-parts/assets/js', 'frontend.js' ), |
| 34 |
'js/helloplus-editor': path.resolve( modulesDir, 'template-parts/assets/js', 'editor.js' ), |
| 35 |
|
| 36 |
// Forms module |
| 37 |
'css/helloplus-forms': path.resolve( modulesDir, 'forms/assets/scss/widgets', 'hello-plus-forms.scss' ), |
| 38 |
'js/helloplus-forms-editor': path.resolve( modulesDir, 'forms/assets/js', 'editor.js' ), |
| 39 |
'js/helloplus-forms-fe': path.resolve( modulesDir, 'forms/assets/js/frontend', 'frontend.js' ), |
| 40 |
|
| 41 |
// Classes |
| 42 |
'css/helloplus-button': path.resolve( process.cwd(), 'assets/dev/scss', 'ehp-button.scss' ), |
| 43 |
'css/helloplus-image': path.resolve( process.cwd(), 'assets/dev/scss', 'ehp-image.scss' ), |
| 44 |
'css/helloplus-shapes': path.resolve( process.cwd(), 'assets/dev/scss', 'ehp-shapes.scss' ), |
| 45 |
}; |
| 46 |
|
| 47 |
module.exports = { |
| 48 |
...defaultConfig, |
| 49 |
...{ |
| 50 |
entry: entryPoints, |
| 51 |
output: { |
| 52 |
...defaultConfig.output, |
| 53 |
path: path.resolve( __dirname, './build' ), |
| 54 |
}, |
| 55 |
plugins: [ |
| 56 |
// Include WP's plugin config. |
| 57 |
...defaultConfig.plugins, |
| 58 |
|
| 59 |
new CopyWebpackPlugin( { |
| 60 |
patterns: [ |
| 61 |
{ |
| 62 |
from: path.resolve( modulesDir, 'content/assets/images' ), |
| 63 |
to: imagesPath, |
| 64 |
}, |
| 65 |
{ |
| 66 |
from: path.resolve( modulesDir, 'forms/assets/images' ), |
| 67 |
to: imagesPath, |
| 68 |
}, |
| 69 |
{ |
| 70 |
from: path.resolve( modulesDir, 'template-parts/assets/images' ), |
| 71 |
to: imagesPath, |
| 72 |
}, |
| 73 |
], |
| 74 |
} ), |
| 75 |
|
| 76 |
// Removes the empty `.js` files generated by webpack but |
| 77 |
// sets it after WP has generated its `*.asset.php` file. |
| 78 |
new RemoveEmptyScriptsPlugin( { |
| 79 |
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS, |
| 80 |
} ), |
| 81 |
], |
| 82 |
}, |
| 83 |
}; |
| 84 |
|