2021-11-05 01:10:31 +00:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
|
|
|
const WebpackTerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const WebpackCopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const path = require('path');
|
2021-11-05 01:29:43 +00:00
|
|
|
const wpScriptConfig = require('@wordpress/scripts/config/webpack.config');
|
|
|
|
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');
|
2022-02-10 16:23:06 +01:00
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2021-10-08 15:36:04 +02:00
|
|
|
|
2021-11-05 01:10:31 +00:00
|
|
|
const globalPrefix = 'MailPoetLib';
|
|
|
|
const PRODUCTION_ENV = process.env.NODE_ENV === 'production';
|
2019-01-09 14:38:10 +01:00
|
|
|
const manifestSeed = {};
|
2015-08-17 14:23:46 +03:00
|
|
|
|
2022-08-08 16:47:57 +02:00
|
|
|
const stats = {
|
|
|
|
preset: 'minimal',
|
|
|
|
assets: false,
|
|
|
|
modules: false,
|
|
|
|
chunks: true,
|
|
|
|
};
|
|
|
|
|
2017-06-14 22:40:21 -04:00
|
|
|
// Base config
|
2019-01-09 14:38:10 +01:00
|
|
|
const baseConfig = {
|
2022-08-08 16:47:57 +02:00
|
|
|
stats,
|
2022-08-08 14:18:17 +02:00
|
|
|
ignoreWarnings: [
|
|
|
|
(warnings) => {
|
|
|
|
// Todo: remove this if statement per MAILPOET-4544
|
|
|
|
if (
|
|
|
|
warnings &&
|
|
|
|
[
|
|
|
|
'AssetsOverSizeLimitWarning',
|
|
|
|
'EntrypointsOverSizeLimitWarning',
|
|
|
|
'NoAsyncChunksWarning',
|
|
|
|
].includes(warnings.name)
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only show warnings when watching
|
|
|
|
if (process.env.WEBPACK_WATCH || process.argv.includes('--watch')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (warnings) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
console.warn(warnings);
|
|
|
|
process.emitWarning(warnings); // emit for listeners
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
],
|
2021-11-05 01:10:31 +00:00
|
|
|
mode: PRODUCTION_ENV ? 'production' : 'development',
|
|
|
|
devtool: PRODUCTION_ENV ? undefined : 'eval-source-map',
|
2017-06-14 22:40:21 -04:00
|
|
|
cache: true,
|
2021-08-10 15:00:56 +02:00
|
|
|
bail: PRODUCTION_ENV,
|
2015-08-17 14:23:46 +03:00
|
|
|
context: __dirname,
|
2018-06-13 13:33:27 +01:00
|
|
|
watchOptions: {
|
2015-10-21 15:24:51 -04:00
|
|
|
aggregateTimeout: 300,
|
2021-10-08 15:36:04 +02:00
|
|
|
poll: true,
|
2015-10-21 15:24:51 -04:00
|
|
|
},
|
2019-01-09 09:29:28 +01:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
2021-10-08 15:36:04 +02:00
|
|
|
new WebpackTerserPlugin({
|
2019-01-09 11:49:19 +01:00
|
|
|
terserOptions: {
|
2019-01-14 12:49:30 +01:00
|
|
|
// preserve identifier names for easier debugging & support
|
2019-01-09 09:29:28 +01:00
|
|
|
mangle: false,
|
|
|
|
},
|
2019-02-05 15:50:05 +03:00
|
|
|
parallel: false,
|
2019-01-09 09:29:28 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
output: {
|
2021-11-05 01:10:31 +00:00
|
|
|
publicPath: '', // This is needed to have correct names in WebpackManifestPlugin
|
|
|
|
path: path.join(__dirname, 'assets/dist/js'),
|
2022-10-19 18:37:34 +02:00
|
|
|
filename: '[name].js',
|
|
|
|
chunkFilename: '[name].chunk.js',
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
2021-11-05 01:10:31 +00:00
|
|
|
modules: ['node_modules', 'assets/js/src'],
|
2021-09-08 15:37:29 +02:00
|
|
|
fallback: {
|
|
|
|
fs: false,
|
2022-07-19 15:58:10 +02:00
|
|
|
path: false, // path is used in css module, but we don't use the functionality which requires it
|
2021-09-08 15:37:29 +02:00
|
|
|
},
|
2021-11-05 01:10:31 +00:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
2015-08-17 14:23:46 +03:00
|
|
|
alias: {
|
2021-11-05 01:10:31 +00:00
|
|
|
handlebars: 'handlebars/dist/handlebars.js',
|
|
|
|
'backbone.marionette': 'backbone.marionette/lib/backbone.marionette',
|
|
|
|
'backbone.supermodel$':
|
|
|
|
'backbone.supermodel/build/backbone.supermodel.js',
|
|
|
|
'sticky-kit': 'vendor/jquery.sticky-kit.js',
|
|
|
|
interact$: 'interact.js/interact.js',
|
|
|
|
spectrum$: 'spectrum-colorpicker/spectrum.js',
|
|
|
|
'wp-js-hooks': path.resolve(__dirname, 'assets/js/src/hooks.js'),
|
|
|
|
blob$: 'blob-tmp/Blob.js',
|
|
|
|
chai: 'chai/index.js',
|
|
|
|
papaparse: 'papaparse/papaparse.min.js',
|
|
|
|
html2canvas: 'html2canvas/dist/html2canvas.js',
|
|
|
|
asyncqueue: 'vendor/jquery.asyncqueue.js',
|
2023-07-19 09:58:11 +02:00
|
|
|
'@woocommerce/settings': path.resolve(
|
|
|
|
__dirname,
|
2024-06-13 16:12:55 +02:00
|
|
|
'assets/js/src/mock-woocommerce-settings.ts',
|
2023-07-19 09:58:11 +02:00
|
|
|
),
|
|
|
|
'@automattic/tour-kit': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'assets/js/src/mock-empty-module.js',
|
|
|
|
),
|
2015-08-26 18:24:43 +03:00
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2022-02-16 09:13:17 +01:00
|
|
|
plugins: PRODUCTION_ENV ? [] : [new ForkTsCheckerWebpackPlugin()],
|
2015-08-17 14:23:46 +03:00
|
|
|
module: {
|
2020-11-16 12:12:23 +01:00
|
|
|
noParse: /node_modules\/lodash\/lodash\.js/,
|
2018-06-13 13:33:27 +01:00
|
|
|
rules: [
|
2015-08-17 14:23:46 +03:00
|
|
|
{
|
2020-02-26 14:14:31 +01:00
|
|
|
test: /\.(j|t)sx?$/,
|
2019-02-20 11:20:33 +01:00
|
|
|
exclude: /(node_modules|src\/vendor)/,
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'babel-loader',
|
2023-01-26 17:05:03 +01:00
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
2015-08-21 13:24:06 +03:00
|
|
|
},
|
|
|
|
{
|
2022-08-08 16:24:40 +02:00
|
|
|
include: path.resolve(
|
|
|
|
__dirname,
|
2023-09-26 14:17:21 +02:00
|
|
|
'assets/js/src/webpack-admin-expose.js',
|
2022-08-08 16:24:40 +02:00
|
|
|
),
|
2021-12-06 17:20:01 +03:00
|
|
|
loader: 'expose-loader',
|
2022-08-08 16:24:40 +02:00
|
|
|
options: { exposes: globalPrefix },
|
2021-12-06 17:20:01 +03:00
|
|
|
},
|
2017-02-28 17:58:04 +03:00
|
|
|
{
|
2022-08-08 16:24:40 +02:00
|
|
|
include: require.resolve('underscore'),
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2022-08-08 16:24:40 +02:00
|
|
|
exposes: '_',
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2017-02-28 17:58:04 +03:00
|
|
|
},
|
2015-11-05 17:17:54 +02:00
|
|
|
{
|
|
|
|
include: /Blob.js$/,
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'exports-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-11-05 01:10:31 +00:00
|
|
|
exports: 'default window.Blob',
|
2021-10-08 15:36:04 +02:00
|
|
|
},
|
2015-11-05 17:17:54 +02:00
|
|
|
},
|
2015-08-21 13:24:06 +03:00
|
|
|
{
|
2015-09-09 14:05:34 +03:00
|
|
|
test: /backbone.supermodel/,
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'exports-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-11-05 01:10:31 +00:00
|
|
|
exports: 'default Backbone.SuperModel',
|
2021-10-08 15:36:04 +02:00
|
|
|
},
|
2015-08-21 13:24:06 +03:00
|
|
|
},
|
2016-01-05 15:01:30 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('velocity-animate'),
|
|
|
|
loader: 'imports-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
|
|
|
imports: {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'jQuery',
|
|
|
|
moduleName: 'jquery',
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
2016-01-05 15:01:30 +02:00
|
|
|
},
|
2019-05-23 08:34:08 +02:00
|
|
|
{
|
|
|
|
test: /node_modules\/tinymce/,
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'string-replace-loader',
|
2019-05-23 08:34:08 +02:00
|
|
|
options: {
|
|
|
|
// prefix TinyMCE to avoid conflicts with other plugins
|
|
|
|
multiple: [
|
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
search: 'window\\.tinymce',
|
|
|
|
replace: 'window.mailpoetTinymce',
|
|
|
|
flags: 'g',
|
2019-05-23 08:34:08 +02:00
|
|
|
},
|
2023-01-31 16:26:52 +01:00
|
|
|
{
|
|
|
|
search: 'window\\.tinyMCE',
|
|
|
|
replace: 'window.mailpoetTinyMCE',
|
|
|
|
flags: 'g',
|
|
|
|
},
|
2019-05-23 08:34:08 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
search: 'tinymce\\.util',
|
|
|
|
replace: 'window.mailpoetTinymce.util',
|
|
|
|
flags: 'g',
|
2019-05-23 08:34:08 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
search: "resolve\\('tinymce",
|
|
|
|
replace: "resolve('mailpoetTinymce",
|
|
|
|
flags: 'g',
|
2019-05-23 08:34:08 +02:00
|
|
|
},
|
2024-06-24 15:42:47 +02:00
|
|
|
{
|
|
|
|
search: 'tinymce.Resource',
|
|
|
|
replace: 'mailpoetTinymce.Resource',
|
|
|
|
flags: 'g',
|
|
|
|
},
|
2019-05-23 08:34:08 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-10-08 15:36:04 +02:00
|
|
|
],
|
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
};
|
|
|
|
|
2017-06-14 22:40:21 -04:00
|
|
|
// Admin config
|
2019-01-09 14:38:10 +01:00
|
|
|
const adminConfig = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'admin',
|
2015-08-17 14:23:46 +03:00
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
vendor: 'webpack-vendor-index.jsx',
|
|
|
|
mailpoet: 'webpack-mailpoet-index.jsx',
|
|
|
|
admin_vendor: ['prop-types', 'lodash', 'webpack-admin-expose.js'], // libraries shared between free and premium plugin
|
|
|
|
admin: 'webpack-admin-index.tsx',
|
2022-02-10 11:06:35 +01:00
|
|
|
automation: 'automation/automation.tsx',
|
2022-05-13 10:42:46 +02:00
|
|
|
automation_editor: 'automation/editor/index.tsx',
|
2023-05-11 08:49:57 +03:00
|
|
|
automation_analytics:
|
|
|
|
'automation/integrations/mailpoet/analytics/index.tsx',
|
2022-09-12 11:03:28 +03:00
|
|
|
automation_templates: 'automation/templates/index.tsx',
|
2023-09-26 14:17:21 +02:00
|
|
|
newsletter_editor: 'newsletter-editor/webpack-index.jsx',
|
|
|
|
form_editor: 'form-editor/form-editor.jsx',
|
2021-11-05 01:10:31 +00:00
|
|
|
settings: 'settings/index.tsx',
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2019-05-22 14:58:41 +02:00
|
|
|
plugins: [
|
|
|
|
...baseConfig.plugins,
|
|
|
|
|
2021-10-08 15:36:04 +02:00
|
|
|
new WebpackCopyPlugin({
|
2020-06-04 10:11:19 +02:00
|
|
|
patterns: [
|
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
from: 'node_modules/tinymce/skins/ui/oxide',
|
|
|
|
to: 'skins/ui/oxide',
|
2020-06-04 10:11:19 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2019-05-22 14:58:41 +02:00
|
|
|
],
|
2019-01-09 09:29:28 +01:00
|
|
|
optimization: {
|
2021-11-05 01:10:31 +00:00
|
|
|
runtimeChunk: 'single',
|
2019-01-09 09:29:28 +01:00
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
2021-09-14 14:27:24 +02:00
|
|
|
commons: {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'commons',
|
|
|
|
chunks: 'initial',
|
2021-09-14 14:27:24 +02:00
|
|
|
minChunks: 2,
|
|
|
|
},
|
2021-09-08 16:17:24 +02:00
|
|
|
},
|
2021-10-08 15:36:04 +02:00
|
|
|
},
|
2019-01-09 09:29:28 +01:00
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
externals: {
|
2021-11-05 01:10:31 +00:00
|
|
|
jquery: 'jQuery',
|
2021-09-08 16:17:24 +02:00
|
|
|
},
|
2017-06-14 22:40:21 -04:00
|
|
|
};
|
2015-08-17 14:23:46 +03:00
|
|
|
|
2017-06-14 22:40:21 -04:00
|
|
|
// Public config
|
2019-01-09 14:38:10 +01:00
|
|
|
const publicConfig = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'public',
|
2015-08-17 14:23:46 +03:00
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
public: 'webpack-public-index.jsx',
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2018-11-28 14:06:02 +01:00
|
|
|
plugins: [
|
2018-12-03 15:44:35 +01:00
|
|
|
...baseConfig.plugins,
|
|
|
|
|
2018-11-28 14:06:02 +01:00
|
|
|
// replace MailPoet definition with a smaller version for public
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
2022-02-16 08:57:02 +01:00
|
|
|
/mailpoet\.ts/,
|
2023-09-26 14:17:21 +02:00
|
|
|
'./mailpoet-public.ts',
|
2018-11-28 14:06:02 +01:00
|
|
|
),
|
|
|
|
],
|
2015-08-17 14:23:46 +03:00
|
|
|
externals: {
|
2021-11-05 01:10:31 +00:00
|
|
|
jquery: 'jQuery',
|
2021-10-08 15:36:04 +02:00
|
|
|
},
|
2017-06-14 22:40:21 -04:00
|
|
|
};
|
2015-08-17 14:23:46 +03:00
|
|
|
|
2019-11-27 11:06:41 +01:00
|
|
|
// Newsletter Editor Tests Config
|
2019-01-09 14:38:10 +01:00
|
|
|
const testConfig = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'test',
|
2024-08-02 14:20:16 +02:00
|
|
|
mode: PRODUCTION_ENV ? 'production' : 'development', // Add mode directly to testConfig
|
2015-08-17 14:23:46 +03:00
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
vendor: 'webpack-vendor-index.jsx',
|
2015-08-26 18:24:43 +03:00
|
|
|
testNewsletterEditor: [
|
2023-09-26 14:17:21 +02:00
|
|
|
'webpack-mailpoet-index.jsx',
|
|
|
|
'newsletter-editor/webpack-index.jsx',
|
2015-08-26 18:24:43 +03:00
|
|
|
|
2021-11-05 01:10:31 +00:00
|
|
|
'components/config.spec.js',
|
|
|
|
'components/content.spec.js',
|
|
|
|
'components/heading.spec.js',
|
|
|
|
'components/history.spec.js',
|
|
|
|
'components/save.spec.js',
|
|
|
|
'components/sidebar.spec.js',
|
|
|
|
'components/styles.spec.js',
|
|
|
|
'components/communication.spec.js',
|
2015-08-26 18:24:43 +03:00
|
|
|
|
2023-09-26 14:17:21 +02:00
|
|
|
'blocks/automated-latest-content-layout.spec.js',
|
2021-11-05 01:10:31 +00:00
|
|
|
'blocks/button.spec.js',
|
|
|
|
'blocks/container.spec.js',
|
2023-01-26 18:53:26 +01:00
|
|
|
'blocks/coupon.spec.js',
|
2021-11-05 01:10:31 +00:00
|
|
|
'blocks/divider.spec.js',
|
|
|
|
'blocks/footer.spec.js',
|
|
|
|
'blocks/header.spec.js',
|
|
|
|
'blocks/image.spec.js',
|
|
|
|
'blocks/posts.spec.js',
|
|
|
|
'blocks/products.spec.js',
|
|
|
|
'blocks/social.spec.js',
|
|
|
|
'blocks/spacer.spec.js',
|
|
|
|
'blocks/text.spec.js',
|
2015-08-26 18:24:43 +03:00
|
|
|
],
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2024-06-28 13:29:38 +02:00
|
|
|
module: {
|
|
|
|
...baseConfig.module,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
exclude: /(node_modules|src\/vendor)/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
resolve: { fullySpecified: false },
|
|
|
|
options: {
|
|
|
|
presets: [['@babel/preset-env', { modules: 'commonjs' }]],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...baseConfig.module.rules,
|
|
|
|
],
|
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
output: {
|
2021-11-05 01:10:31 +00:00
|
|
|
path: path.join(
|
|
|
|
__dirname,
|
2023-09-26 14:17:21 +02:00
|
|
|
'tests/javascript-newsletter-editor/testBundles',
|
2021-11-05 01:10:31 +00:00
|
|
|
),
|
|
|
|
filename: '[name].js',
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2018-11-28 14:06:02 +01:00
|
|
|
plugins: [
|
|
|
|
// replace MailPoet definition with a smaller version for public
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/mailpoet\.js/,
|
2023-09-26 14:17:21 +02:00
|
|
|
'./mailpoet-tests.js',
|
2018-11-28 14:06:02 +01:00
|
|
|
),
|
|
|
|
],
|
2015-08-17 14:23:46 +03:00
|
|
|
resolve: {
|
2018-06-13 13:33:27 +01:00
|
|
|
modules: [
|
2021-11-05 01:10:31 +00:00
|
|
|
'node_modules',
|
|
|
|
'assets/js/src',
|
2023-09-26 14:17:21 +02:00
|
|
|
'tests/javascript-newsletter-editor/newsletter-editor',
|
2015-08-26 18:24:43 +03:00
|
|
|
],
|
2021-11-05 01:10:31 +00:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
2015-08-26 18:24:43 +03:00
|
|
|
alias: {
|
2021-11-05 01:10:31 +00:00
|
|
|
handlebars: 'handlebars/dist/handlebars.js',
|
|
|
|
'sticky-kit': 'vendor/jquery.sticky-kit.js',
|
|
|
|
'backbone.marionette': 'backbone.marionette/lib/backbone.marionette',
|
|
|
|
'backbone.supermodel$':
|
|
|
|
'backbone.supermodel/build/backbone.supermodel.js',
|
|
|
|
blob$: 'blob-tmp/Blob.js',
|
|
|
|
'wp-js-hooks': path.resolve(__dirname, 'assets/js/src/hooks.js'),
|
2015-08-26 18:24:43 +03:00
|
|
|
},
|
2021-09-08 15:37:29 +02:00
|
|
|
fallback: {
|
|
|
|
fs: false,
|
|
|
|
},
|
2015-08-26 18:24:43 +03:00
|
|
|
},
|
|
|
|
externals: {
|
2021-11-05 01:10:31 +00:00
|
|
|
jquery: 'jQuery',
|
|
|
|
interact: 'interact',
|
|
|
|
spectrum: 'spectrum',
|
2019-10-16 15:14:25 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-05-19 16:57:02 +02:00
|
|
|
// Form preview config
|
|
|
|
const formPreviewConfig = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'form_preview',
|
2020-05-19 16:57:02 +02:00
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
form_preview: 'form-editor/form-preview.ts',
|
2020-05-19 16:57:02 +02:00
|
|
|
},
|
|
|
|
externals: {
|
2021-11-05 01:10:31 +00:00
|
|
|
jquery: 'jQuery',
|
2020-05-19 16:57:02 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-30 14:05:51 +01:00
|
|
|
// Block config
|
|
|
|
const postEditorBlock = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'post_editor_block',
|
2021-11-01 17:07:19 +00:00
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
post_editor_block: 'post-editor-block/blocks.jsx',
|
2021-11-01 17:07:19 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-11-05 01:29:43 +00:00
|
|
|
// Marketing Optin config
|
|
|
|
function requestToExternal(request) {
|
|
|
|
const wcDepMap = {
|
|
|
|
'@woocommerce/settings': ['wc', 'wcSettings'],
|
|
|
|
'@woocommerce/blocks-checkout': ['wc', 'blocksCheckout'],
|
|
|
|
};
|
|
|
|
if (wcDepMap[request]) {
|
|
|
|
return wcDepMap[request];
|
|
|
|
}
|
2021-11-05 13:27:00 +01:00
|
|
|
// DependencyExtractionWebpackPlugin has native handling for @wordpress/*
|
|
|
|
// packages, for that handling to kick in, we must not return anything from
|
|
|
|
// function.
|
2021-11-05 13:36:44 +01:00
|
|
|
/* eslint-disable-next-line consistent-return, no-useless-return */
|
2021-11-05 13:27:00 +01:00
|
|
|
return;
|
2021-11-05 01:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestToHandle(request) {
|
|
|
|
const wcHandleMap = {
|
|
|
|
'@woocommerce/settings': 'wc-settings',
|
|
|
|
'@woocommerce/blocks-checkout': 'wc-blocks-checkout',
|
|
|
|
};
|
|
|
|
if (wcHandleMap[request]) {
|
|
|
|
return wcHandleMap[request];
|
|
|
|
}
|
2021-11-05 13:27:00 +01:00
|
|
|
// DependencyExtractionWebpackPlugin has native handling for @wordpress/*
|
|
|
|
// packages, for that handling to kick in, we must not return anything from
|
|
|
|
// function.
|
2021-11-05 13:36:44 +01:00
|
|
|
/* eslint-disable-next-line consistent-return, no-useless-return */
|
2021-11-05 13:27:00 +01:00
|
|
|
return;
|
2021-11-05 01:29:43 +00:00
|
|
|
}
|
|
|
|
const marketingOptinBlock = Object.assign({}, wpScriptConfig, {
|
2022-08-08 16:47:57 +02:00
|
|
|
stats,
|
2021-11-05 01:29:43 +00:00
|
|
|
name: 'marketing_optin_block',
|
|
|
|
entry: {
|
2023-09-26 14:17:21 +02:00
|
|
|
'marketing-optin-block': '/assets/js/src/marketing-optin-block/index.tsx',
|
2022-08-05 12:31:44 +02:00
|
|
|
'marketing-optin-block-frontend':
|
2023-09-26 14:17:21 +02:00
|
|
|
'/assets/js/src/marketing-optin-block/frontend.ts',
|
2021-11-05 01:29:43 +00:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
2023-09-26 14:17:21 +02:00
|
|
|
path: path.join(__dirname, 'assets/dist/js/marketing-optin-block'),
|
2021-11-05 01:29:43 +00:00
|
|
|
},
|
|
|
|
module: Object.assign({}, wpScriptConfig.module, {
|
|
|
|
rules: [
|
|
|
|
...wpScriptConfig.module.rules,
|
|
|
|
{
|
|
|
|
test: /\.(t|j)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: ['@wordpress/babel-preset-default'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
2022-08-05 12:31:44 +02:00
|
|
|
// use only needed plugins from wpScriptConfig and add the custom ones
|
2021-11-05 01:29:43 +00:00
|
|
|
plugins: [
|
|
|
|
...wpScriptConfig.plugins.filter(
|
|
|
|
(plugin) =>
|
2022-08-05 12:31:44 +02:00
|
|
|
plugin.constructor.pluginName === 'mini-css-extract-plugin' ||
|
|
|
|
plugin.constructor.name === 'CleanWebpackPlugin',
|
2021-11-05 01:29:43 +00:00
|
|
|
),
|
|
|
|
new DependencyExtractionWebpackPlugin({
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
}),
|
2021-11-18 14:07:09 +01:00
|
|
|
new WebpackCopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
2023-09-26 14:17:21 +02:00
|
|
|
from: 'assets/js/src/marketing-optin-block/block.json',
|
2021-11-18 14:07:09 +01:00
|
|
|
to: 'block.json',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-11-05 01:29:43 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2024-05-02 15:35:17 +01:00
|
|
|
const emailEditorBlocks = Object.assign({}, wpScriptConfig, {
|
|
|
|
name: 'email-editor-blocks',
|
|
|
|
entry: {
|
|
|
|
'powered-by-mailpoet-block':
|
2024-11-08 18:01:20 +01:00
|
|
|
'/assets/js/src/mailpoet-custom-email-editor-blocks/powered-by-mailpoet/block.tsx',
|
2025-01-10 11:48:25 +01:00
|
|
|
mailpoet: '/assets/js/src/mailpoet.ts',
|
2024-05-02 15:35:17 +01:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.join(__dirname, 'assets/dist/js/email-editor-blocks'),
|
|
|
|
},
|
|
|
|
module: Object.assign({}, wpScriptConfig.module, {
|
|
|
|
rules: [
|
|
|
|
...wpScriptConfig.module.rules,
|
|
|
|
{
|
|
|
|
test: /\.(t|j)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: ['@wordpress/babel-preset-default'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
resolve: {
|
2025-01-10 11:48:25 +01:00
|
|
|
alias: {
|
|
|
|
mailpoet: path.resolve(__dirname, 'assets/js/src/mailpoet.ts'),
|
|
|
|
},
|
2024-05-02 15:35:17 +01:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
// use only needed plugins from wpScriptConfig and add the custom ones
|
|
|
|
plugins: [
|
|
|
|
...wpScriptConfig.plugins.filter(
|
|
|
|
(plugin) =>
|
|
|
|
plugin.constructor.pluginName === 'mini-css-extract-plugin' ||
|
|
|
|
plugin.constructor.name === 'CleanWebpackPlugin',
|
|
|
|
),
|
|
|
|
new DependencyExtractionWebpackPlugin({
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2023-09-25 13:27:31 +02:00
|
|
|
const emailEditorCustom = Object.assign({}, wpScriptConfig, {
|
2023-10-12 20:01:48 +02:00
|
|
|
name: 'email_editor',
|
2023-09-25 13:27:31 +02:00
|
|
|
entry: {
|
2024-11-04 17:15:10 +01:00
|
|
|
email_editor: '../packages/js/email-editor/src/index.ts',
|
2023-09-25 13:27:31 +02:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
2023-10-12 20:01:48 +02:00
|
|
|
path: path.join(__dirname, 'assets/dist/js/email-editor'),
|
2023-09-25 13:27:31 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
...wpScriptConfig.resolve,
|
2024-11-05 11:24:43 +01:00
|
|
|
modules: ['node_modules', '../packages/js/email-editor'],
|
2023-09-25 13:27:31 +02:00
|
|
|
},
|
2024-11-05 11:24:43 +01:00
|
|
|
module: Object.assign({}, wpScriptConfig.module, {
|
|
|
|
rules: [
|
|
|
|
...wpScriptConfig.module.rules,
|
|
|
|
{
|
|
|
|
test: /\.(t|j)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: ['@wordpress/babel-preset-default'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2023-12-20 09:25:28 +01:00
|
|
|
plugins: PRODUCTION_ENV
|
|
|
|
? wpScriptConfig.plugins
|
2024-01-22 14:33:00 +01:00
|
|
|
: [...wpScriptConfig.plugins, new ForkTsCheckerWebpackPlugin()],
|
2023-09-25 13:27:31 +02:00
|
|
|
});
|
|
|
|
|
2024-12-15 19:11:08 +01:00
|
|
|
// Temporary solution to build rich-text package for email editor
|
|
|
|
const emailEditorRichText = Object.assign({}, wpScriptConfig, {
|
|
|
|
name: 'email-editor-rich-text',
|
|
|
|
entry: {
|
|
|
|
'rich-text': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../packages/js/email-editor/node_modules/@wordpress/rich-text/build/index.js',
|
|
|
|
),
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.join(__dirname, 'assets/dist/js/email-editor'),
|
|
|
|
library: ['wp', 'richText'], // Expose the richText package to the global wp object
|
|
|
|
libraryTarget: 'window', // Ensure it is accessible globally
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
module: Object.assign({}, wpScriptConfig.module, {
|
|
|
|
rules: [
|
|
|
|
...wpScriptConfig.module.rules,
|
|
|
|
{
|
|
|
|
test: /\.(t|j)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: ['@wordpress/babel-preset-default'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2024-11-18 13:44:36 +01:00
|
|
|
const emailEditorIntegration = Object.assign({}, wpScriptConfig, {
|
|
|
|
name: 'email_editor_integration',
|
|
|
|
entry: {
|
|
|
|
email_editor_integration: 'mailpoet-email-editor-integration/index.ts',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.join(__dirname, 'assets/dist/js/email_editor_integration'),
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
...wpScriptConfig.resolve,
|
|
|
|
modules: ['node_modules', 'assets/js/src'],
|
|
|
|
},
|
|
|
|
plugins: PRODUCTION_ENV
|
|
|
|
? wpScriptConfig.plugins
|
|
|
|
: [...wpScriptConfig.plugins, new ForkTsCheckerWebpackPlugin()],
|
|
|
|
});
|
|
|
|
|
2021-10-08 15:36:04 +02:00
|
|
|
const configs = [
|
|
|
|
publicConfig,
|
|
|
|
adminConfig,
|
2023-09-25 13:27:31 +02:00
|
|
|
emailEditorCustom,
|
2021-10-08 15:36:04 +02:00
|
|
|
formPreviewConfig,
|
|
|
|
postEditorBlock,
|
2021-11-05 01:29:43 +00:00
|
|
|
marketingOptinBlock,
|
2024-05-02 15:35:17 +01:00
|
|
|
emailEditorBlocks,
|
2024-11-18 13:44:36 +01:00
|
|
|
emailEditorIntegration,
|
2024-12-15 19:11:08 +01:00
|
|
|
emailEditorRichText,
|
2021-10-08 15:36:04 +02:00
|
|
|
];
|
|
|
|
|
2023-12-20 10:44:10 +01:00
|
|
|
module.exports = (env) => {
|
|
|
|
// Include tests build only if requested
|
|
|
|
if (env && env.BUILD_TESTS === 'build') {
|
|
|
|
configs.push(testConfig);
|
2021-11-05 01:29:43 +00:00
|
|
|
}
|
2024-08-02 14:20:16 +02:00
|
|
|
|
|
|
|
// If only the test build is requested
|
|
|
|
if (env && env.BUILD_ONLY_TESTS === 'true') {
|
|
|
|
return [testConfig];
|
|
|
|
}
|
|
|
|
|
2023-12-20 10:44:10 +01:00
|
|
|
return configs.map((conf) => {
|
|
|
|
const config = Object.assign({}, conf);
|
|
|
|
if (
|
|
|
|
config.name === 'marketing_optin_block' ||
|
2024-11-18 13:44:36 +01:00
|
|
|
config.name === 'email_editor' ||
|
|
|
|
config.name === 'email_editor_integration'
|
2023-12-20 10:44:10 +01:00
|
|
|
) {
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
if (config.name !== 'test') {
|
|
|
|
config.plugins = config.plugins || [];
|
|
|
|
config.plugins.push(
|
|
|
|
new WebpackManifestPlugin({
|
|
|
|
// create single manifest file for all Webpack configs
|
|
|
|
seed: manifestSeed,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Object.assign({}, baseConfig, config);
|
|
|
|
});
|
|
|
|
};
|