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');
|
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
|
|
|
|
2017-06-14 22:40:21 -04:00
|
|
|
// Base config
|
2019-01-09 14:38:10 +01:00
|
|
|
const baseConfig = {
|
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'),
|
|
|
|
filename: (PRODUCTION_ENV) ? '[name].[fullhash:8].js' : '[name].js',
|
|
|
|
chunkFilename: (PRODUCTION_ENV) ? '[name].[fullhash:8].chunk.js' : '[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,
|
2021-10-08 15:36:04 +02:00
|
|
|
// We need path polyfill so that eslint is able to lint webpack.config.js
|
|
|
|
// and it is imported in css module, but we don't use the functionality which requires it
|
2021-11-05 01:10:31 +00:00
|
|
|
path: require.resolve('path-browserify'),
|
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',
|
2015-08-26 18:24:43 +03:00
|
|
|
},
|
2015-08-17 14:23:46 +03:00
|
|
|
},
|
2021-06-30 16:18:27 +02:00
|
|
|
plugins: [],
|
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',
|
2015-08-21 13:24:06 +03:00
|
|
|
},
|
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('underscore'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-11-05 01:10:31 +00:00
|
|
|
exposes: '_',
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2015-08-21 13:24:06 +03:00
|
|
|
},
|
2018-06-06 15:13:39 +01:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('react-tooltip'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.ReactTooltip`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2018-06-06 15:13:39 +01:00
|
|
|
},
|
2017-03-01 14:30:24 +03:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('react'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.React`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2017-03-01 14:30:24 +03:00
|
|
|
},
|
2017-09-12 16:30:56 +01:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('react-dom'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.ReactDOM`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2017-09-12 16:30:56 +01:00
|
|
|
},
|
2017-04-04 15:37:16 +03:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('react-router-dom'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.ReactRouter`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2017-04-04 15:37:16 +03:00
|
|
|
},
|
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('react-string-replace'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.ReactStringReplace`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
2017-03-01 14:30:24 +03:00
|
|
|
},
|
2017-02-28 17:58:04 +03:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: path.resolve(__dirname, 'assets/js/src/hooks.js'),
|
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
|
|
|
exposes: {
|
2021-10-08 15:36:04 +02:00
|
|
|
globalName: `${globalPrefix}.Hooks`,
|
2021-09-08 16:15:22 +02:00
|
|
|
override: true,
|
|
|
|
},
|
|
|
|
},
|
2017-02-28 17:58:04 +03:00
|
|
|
},
|
2017-04-04 15:37:16 +03:00
|
|
|
{
|
|
|
|
test: /listing.jsx/i,
|
2018-06-13 13:33:27 +01:00
|
|
|
use: [
|
2021-09-08 16:15:22 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.Listing`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
2021-11-05 01:10:31 +00:00
|
|
|
'babel-loader',
|
2018-06-13 13:33:27 +01:00
|
|
|
],
|
2017-04-04 15:37:16 +03:00
|
|
|
},
|
2019-05-15 15:09:14 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: path.resolve(__dirname, 'assets/js/src/help-tooltip.jsx'),
|
2019-05-15 15:09:14 +02:00
|
|
|
use: [
|
2021-09-08 16:15:22 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.HelpTooltip`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
2021-11-05 01:10:31 +00:00
|
|
|
'babel-loader',
|
2021-10-08 15:36:04 +02:00
|
|
|
],
|
2019-05-15 15:09:14 +02:00
|
|
|
},
|
2020-08-27 10:15:09 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: path.resolve(__dirname, 'assets/js/src/common/index.ts'),
|
2020-08-27 10:15:09 +02:00
|
|
|
use: [
|
2021-09-08 16:15:22 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.Common`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
2021-11-05 01:10:31 +00:00
|
|
|
'babel-loader',
|
2021-10-08 15:36:04 +02:00
|
|
|
],
|
2020-08-27 10:15:09 +02: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
|
|
|
},
|
2018-03-29 16:22:08 -04:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
include: require.resolve('classnames'),
|
2018-06-13 13:33:27 +01:00
|
|
|
use: [
|
2021-09-08 16:15:22 +02:00
|
|
|
{
|
2021-11-05 01:10:31 +00:00
|
|
|
loader: 'expose-loader',
|
2021-09-08 16:15:22 +02:00
|
|
|
options: {
|
2021-10-08 15:36:04 +02:00
|
|
|
exposes: `${globalPrefix}.ClassNames`,
|
2021-09-08 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
2021-11-05 01:10:31 +00:00
|
|
|
'babel-loader',
|
2021-10-08 15:36:04 +02:00
|
|
|
],
|
2018-03-29 16:22:08 -04: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
|
|
|
},
|
|
|
|
{
|
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
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
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: {
|
2021-11-05 01:10:31 +00:00
|
|
|
vendor: 'webpack_vendor_index.jsx',
|
|
|
|
mailpoet: 'webpack_mailpoet_index.jsx',
|
2021-09-14 14:49:32 +02:00
|
|
|
// Admin vendor contains libraries shared between free and premium plugin
|
2018-12-11 12:11:39 +01:00
|
|
|
admin_vendor: [
|
2021-11-05 01:10:31 +00:00
|
|
|
'react',
|
|
|
|
'react-dom',
|
|
|
|
require.resolve('react-router-dom'),
|
|
|
|
'react-string-replace',
|
|
|
|
'prop-types',
|
|
|
|
'classnames',
|
|
|
|
'lodash',
|
|
|
|
'help-tooltip.jsx',
|
|
|
|
'listing/listing.jsx',
|
|
|
|
'common/index.ts',
|
2018-12-11 12:11:39 +01:00
|
|
|
],
|
2021-11-05 01:10:31 +00:00
|
|
|
admin: 'webpack_admin_index.jsx',
|
|
|
|
newsletter_editor: 'newsletter_editor/webpack_index.jsx',
|
|
|
|
form_editor: 'form_editor/form_editor.jsx',
|
|
|
|
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
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-09-09 14:19:05 +02:00
|
|
|
new webpack.ProvidePlugin({
|
2021-11-05 01:10:31 +00:00
|
|
|
process: 'process/browser',
|
2021-09-09 14:19:05 +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: {
|
2021-11-05 01:10:31 +00: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(
|
|
|
|
/mailpoet\.js/,
|
2021-11-05 01:10:31 +00:00
|
|
|
'./mailpoet_public.js'
|
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
|
|
|
|
2017-06-14 22:40:21 -04:00
|
|
|
// Migrator config
|
2019-01-09 14:38:10 +01:00
|
|
|
const migratorConfig = {
|
2021-11-05 01:10:31 +00:00
|
|
|
name: 'mp2migrator',
|
2017-04-18 19:15:12 +02:00
|
|
|
entry: {
|
2021-11-05 01:10:31 +00:00
|
|
|
mp2migrator: [
|
|
|
|
'mp2migrator.js',
|
|
|
|
],
|
2017-04-18 19:15:12 +02:00
|
|
|
},
|
|
|
|
externals: {
|
2021-11-05 01:10:31 +00:00
|
|
|
jquery: 'jQuery',
|
|
|
|
mailpoet: 'MailPoet',
|
2021-10-08 15:36:04 +02:00
|
|
|
},
|
2017-06-14 22:40:21 -04:00
|
|
|
};
|
2019-01-09 09:29:28 +01: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',
|
2015-08-17 14:23:46 +03:00
|
|
|
entry: {
|
2021-11-05 01:10:31 +00:00
|
|
|
vendor: 'webpack_vendor_index.jsx',
|
2015-08-26 18:24:43 +03:00
|
|
|
testNewsletterEditor: [
|
2021-11-05 01:10:31 +00: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
|
|
|
|
2021-11-05 01:10:31 +00:00
|
|
|
'blocks/automatedLatestContentLayout.spec.js',
|
|
|
|
'blocks/button.spec.js',
|
|
|
|
'blocks/container.spec.js',
|
|
|
|
'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
|
|
|
},
|
|
|
|
output: {
|
2021-11-05 01:10:31 +00:00
|
|
|
path: path.join(__dirname, 'tests/javascript_newsletter_editor/testBundles'),
|
|
|
|
filename: '[name].js',
|
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(
|
|
|
|
/mailpoet\.js/,
|
2021-11-05 01:10:31 +00: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',
|
|
|
|
'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: {
|
2021-11-05 01:10:31 +00: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: {
|
2021-11-05 01:10:31 +00: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, {
|
|
|
|
name: 'marketing_optin_block',
|
|
|
|
entry: {
|
|
|
|
'marketing-optin-block': path.resolve(
|
|
|
|
process.cwd(),
|
|
|
|
'assets/js/src/marketing_optin_block',
|
|
|
|
'index.tsx'
|
|
|
|
),
|
|
|
|
'marketing-optin-block-frontend': path.resolve(
|
|
|
|
process.cwd(),
|
|
|
|
'assets/js/src/marketing_optin_block',
|
2021-11-11 13:27:14 +01:00
|
|
|
'frontend.ts'
|
2021-11-05 01:29:43 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.resolve(process.cwd(), 'assets/dist/js/marketing_optin_block'),
|
|
|
|
},
|
|
|
|
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'],
|
|
|
|
plugins: [
|
|
|
|
require.resolve('@babel/plugin-proposal-class-properties'),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-nullish-coalescing-operator'
|
|
|
|
),
|
|
|
|
].filter(Boolean),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
...wpScriptConfig.plugins.filter(
|
|
|
|
(plugin) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
|
|
),
|
|
|
|
new DependencyExtractionWebpackPlugin({
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
}),
|
2021-11-18 14:07:09 +01:00
|
|
|
new WebpackCopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: 'assets/js/src/marketing_optin_block/block.json',
|
|
|
|
to: 'block.json',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-11-05 01:29:43 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-10-08 15:36:04 +02:00
|
|
|
const configs = [
|
|
|
|
publicConfig,
|
|
|
|
adminConfig,
|
|
|
|
migratorConfig,
|
|
|
|
formPreviewConfig,
|
|
|
|
testConfig,
|
|
|
|
postEditorBlock,
|
2021-11-05 01:29:43 +00:00
|
|
|
marketingOptinBlock,
|
2021-10-08 15:36:04 +02:00
|
|
|
];
|
|
|
|
|
2021-11-05 01:10:31 +00:00
|
|
|
module.exports = configs.map((conf) => {
|
|
|
|
const config = Object.assign({}, conf);
|
2021-11-05 01:29:43 +00:00
|
|
|
if (config.name === 'marketing_optin_block') {
|
|
|
|
return config;
|
|
|
|
}
|
2021-11-05 01:10:31 +00:00
|
|
|
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);
|
|
|
|
});
|