webpack.mix.js (1521B)
1 const path = require('path') 2 const camelCaseDash = (string) => string.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()) 3 const mix = require('laravel-mix') 4 5 // If you add additional WP imports, include them here (could we generate these?) 6 const externals = [ 7 'api-fetch', 8 'block-editor', 9 'blocks', 10 'components', 11 'compose', 12 'data', 13 'date', 14 'htmlEntities', 15 'hooks', 16 'edit-post', 17 'element', 18 'editor', 19 'i18n', 20 'plugins', 21 'viewport', 22 'ajax', 23 'codeEditor', 24 'rich-text', 25 ] 26 const globals = externals.reduce((externals, name) => ({ 27 ...externals, 28 [`@wordpress/${name}`]: `wp.${camelCaseDash(name)}`, 29 }), {}) 30 31 const webpackConfig = (context) => { 32 return { 33 context: context, 34 externals: { 35 wp: 'wp', 36 lodash: 'lodash', 37 fetch: 'fetch', 38 react: 'React', 39 'react-dom': 'ReactDOM', 40 ...globals, 41 }, 42 } 43 } 44 45 mix.js('src/app.js', 'public/build/extendify-sdk.js') 46 .webpackConfig(webpackConfig(path.resolve(__dirname, 'src'))) 47 .react() 48 .setPublicPath('public') 49 .postCss( 50 'src/app.css', 51 'public/build/extendify-sdk.css', 52 [require('tailwindcss')], 53 ) 54 .browserSync({ 55 proxy: 'wordpress.test', 56 open: false, 57 files: ['src/**/*'], 58 }) 59 60 mix.js('editorplus/editorplus.js', 'editorplus/editorplus.min.js') 61 .webpackConfig(webpackConfig(path.resolve(__dirname, 'editorplus'))) 62 .react()