Merge pull request #1725 from mailpoet/webpack-upgrade
Webpack upgrade [MAILPOET-1667]
This commit is contained in:
6
assets/js/src/amd-inject-loader-fixed.js
Normal file
6
assets/js/src/amd-inject-loader-fixed.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
var amdInjectLoader = require('amd-inject-loader');
|
||||||
|
|
||||||
|
// fix original 'amd-inject-loader' for Webpack 4 by adding missing 'options' field to its context
|
||||||
|
module.exports = function amdInjectLoaderFixed(input) {
|
||||||
|
return amdInjectLoader.call(Object.assign({}, this, { options: {} }), input);
|
||||||
|
};
|
1781
package-lock.json
generated
1781
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -50,7 +50,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.2.0",
|
"@babel/core": "^7.2.0",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.2.1",
|
"@babel/plugin-proposal-class-properties": "^7.2.1",
|
||||||
"@babel/preset-env": "^7.2.0",
|
|
||||||
"@babel/plugin-proposal-decorators": "^7.1.6",
|
"@babel/plugin-proposal-decorators": "^7.1.6",
|
||||||
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
|
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
|
||||||
"@babel/plugin-proposal-function-sent": "^7.2.0",
|
"@babel/plugin-proposal-function-sent": "^7.2.0",
|
||||||
@@ -60,13 +59,14 @@
|
|||||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
||||||
"@babel/plugin-syntax-import-meta": "^7.2.0",
|
"@babel/plugin-syntax-import-meta": "^7.2.0",
|
||||||
"@babel/plugin-transform-runtime": "^7.2.0",
|
"@babel/plugin-transform-runtime": "^7.2.0",
|
||||||
|
"@babel/preset-env": "^7.2.0",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
"amd-inject-loader": "~0.5.0",
|
"amd-inject-loader": "~0.5.0",
|
||||||
"babel-eslint": "^10.0.1",
|
"babel-eslint": "^10.0.1",
|
||||||
"babel-loader": "^8.0.4",
|
"babel-loader": "^8.0.4",
|
||||||
"chai": "2.2.0",
|
"chai": "2.2.0",
|
||||||
"chai-jq": "0.0.8",
|
"chai-jq": "0.0.8",
|
||||||
"clean-webpack-plugin": "^0.1.19",
|
"clean-webpack-plugin": "^1.0.0",
|
||||||
"cross-env": "^5.1.5",
|
"cross-env": "^5.1.5",
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^4.19.1",
|
||||||
"eslint-config-airbnb": "^15.0.1",
|
"eslint-config-airbnb": "^15.0.1",
|
||||||
@@ -86,8 +86,9 @@
|
|||||||
"sinon": "1.14.1",
|
"sinon": "1.14.1",
|
||||||
"sinon-chai": "2.7.0",
|
"sinon-chai": "2.7.0",
|
||||||
"stylus": "~0.54.5",
|
"stylus": "~0.54.5",
|
||||||
"webpack": "3.12.0",
|
"terser-webpack-plugin": "^1.2.1",
|
||||||
"webpack-manifest-plugin": "^1.3.2",
|
"webpack": "^4.28.1",
|
||||||
"webpack-md5-hash": "0.0.5"
|
"webpack-cli": "^3.2.1",
|
||||||
|
"webpack-manifest-plugin": "^2.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,7 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
|||||||
<% block after_translations %><% endblock %>
|
<% block after_translations %><% endblock %>
|
||||||
|
|
||||||
<%= javascript(
|
<%= javascript(
|
||||||
|
'admin_vendor_chunk.js',
|
||||||
'admin_vendor.js'
|
'admin_vendor.js'
|
||||||
)%>
|
)%>
|
||||||
|
|
||||||
|
@@ -1,22 +1,31 @@
|
|||||||
var webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
var webpackManifestPlugin = require('webpack-manifest-plugin');
|
const webpackManifestPlugin = require('webpack-manifest-plugin');
|
||||||
var webpackMD5HashPlugin = require('webpack-md5-hash');
|
const webpackCleanPlugin = require('clean-webpack-plugin');
|
||||||
var webpackCleanPlugin = require('clean-webpack-plugin');
|
const webpackTerserPlugin = require('terser-webpack-plugin');
|
||||||
var webpackUglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
const path = require('path');
|
||||||
var _ = require('underscore');
|
const globalPrefix = 'MailPoetLib';
|
||||||
var path = require('path');
|
const PRODUCTION_ENV = process.env.NODE_ENV === 'production';
|
||||||
var globalPrefix = 'MailPoetLib';
|
const manifestSeed = {};
|
||||||
var PRODUCTION_ENV = process.env.NODE_ENV === 'production';
|
|
||||||
var manifestCache = {};
|
|
||||||
|
|
||||||
// Base config
|
// Base config
|
||||||
var baseConfig = {
|
const baseConfig = {
|
||||||
|
mode: PRODUCTION_ENV ? 'production' : 'development',
|
||||||
cache: true,
|
cache: true,
|
||||||
context: __dirname,
|
context: __dirname,
|
||||||
watchOptions: {
|
watchOptions: {
|
||||||
aggregateTimeout: 300,
|
aggregateTimeout: 300,
|
||||||
poll: true
|
poll: true
|
||||||
},
|
},
|
||||||
|
optimization: {
|
||||||
|
minimizer: [
|
||||||
|
new webpackTerserPlugin({
|
||||||
|
terserOptions: {
|
||||||
|
// preserve identifier names for easier debugging & support
|
||||||
|
mangle: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'assets/js'),
|
path: path.join(__dirname, 'assets/js'),
|
||||||
filename: (PRODUCTION_ENV) ? '[name].[hash:8].js' : '[name].js',
|
filename: (PRODUCTION_ENV) ? '[name].[hash:8].js' : '[name].js',
|
||||||
@@ -49,7 +58,7 @@ var baseConfig = {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new webpackCleanPlugin([
|
new webpackCleanPlugin([
|
||||||
'./assets/js/*.*',
|
'./assets/js/*.*',
|
||||||
])
|
]),
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
@@ -224,7 +233,7 @@ var baseConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Admin config
|
// Admin config
|
||||||
var adminConfig = {
|
const adminConfig = {
|
||||||
name: 'admin',
|
name: 'admin',
|
||||||
entry: {
|
entry: {
|
||||||
vendor: 'webpack_vendor_index.jsx',
|
vendor: 'webpack_vendor_index.jsx',
|
||||||
@@ -252,20 +261,42 @@ var adminConfig = {
|
|||||||
form_editor: 'form_editor/webpack_index.jsx',
|
form_editor: 'form_editor/webpack_index.jsx',
|
||||||
newsletter_editor: 'newsletter_editor/webpack_index.jsx',
|
newsletter_editor: 'newsletter_editor/webpack_index.jsx',
|
||||||
},
|
},
|
||||||
plugins: [
|
optimization: {
|
||||||
...baseConfig.plugins,
|
runtimeChunk: {
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'admin_vendor',
|
|
||||||
fileName: 'admin_vendor.js',
|
|
||||||
chunks: ['admin', 'form_editor', 'newsletter_editor'],
|
|
||||||
minChunks: 2
|
|
||||||
}),
|
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'vendor',
|
name: 'vendor',
|
||||||
fileName: 'vendor.js',
|
},
|
||||||
minChunks: Infinity
|
splitChunks: {
|
||||||
})
|
cacheGroups: {
|
||||||
],
|
chunks: 'all',
|
||||||
|
default: false,
|
||||||
|
vendors: false,
|
||||||
|
vendor: {
|
||||||
|
name: 'vendor',
|
||||||
|
chunks: (chunk) => chunk.name === 'vendor',
|
||||||
|
priority: 1,
|
||||||
|
enforce: true,
|
||||||
|
},
|
||||||
|
admin_vendor_chunk: {
|
||||||
|
name: 'admin_vendor_chunk',
|
||||||
|
test: (module, chunks) => {
|
||||||
|
// add all modules from 'admin_vendor' entrypoint
|
||||||
|
if (chunks.some((chunk) => chunk.name === 'admin_vendor')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add admin/form_editor/newsletter_editor shared modules
|
||||||
|
const filteredChunks = chunks.filter((chunk) => {
|
||||||
|
return ['admin', 'form_editor', 'newsletter_editor'].includes(chunk.name);
|
||||||
|
});
|
||||||
|
return filteredChunks.length > 1;
|
||||||
|
},
|
||||||
|
enforce: true,
|
||||||
|
chunks: (chunk) => ['admin_vendor', 'admin', 'form_editor', 'newsletter_editor'].includes(chunk.name),
|
||||||
|
priority: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
externals: {
|
externals: {
|
||||||
'jquery': 'jQuery',
|
'jquery': 'jQuery',
|
||||||
'tinymce': 'tinymce'
|
'tinymce': 'tinymce'
|
||||||
@@ -273,7 +304,7 @@ var adminConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Public config
|
// Public config
|
||||||
var publicConfig = {
|
const publicConfig = {
|
||||||
name: 'public',
|
name: 'public',
|
||||||
entry: {
|
entry: {
|
||||||
public: 'webpack_public_index.jsx',
|
public: 'webpack_public_index.jsx',
|
||||||
@@ -293,7 +324,7 @@ var publicConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Migrator config
|
// Migrator config
|
||||||
var migratorConfig = {
|
const migratorConfig = {
|
||||||
name: 'mp2migrator',
|
name: 'mp2migrator',
|
||||||
entry: {
|
entry: {
|
||||||
mp2migrator: [
|
mp2migrator: [
|
||||||
@@ -305,8 +336,9 @@ var migratorConfig = {
|
|||||||
'mailpoet': 'MailPoet'
|
'mailpoet': 'MailPoet'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test config
|
// Test config
|
||||||
var testConfig = {
|
const testConfig = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
entry: {
|
entry: {
|
||||||
vendor: 'webpack_vendor_index.jsx',
|
vendor: 'webpack_vendor_index.jsx',
|
||||||
@@ -362,6 +394,12 @@ var testConfig = {
|
|||||||
'wp-js-hooks': 'WP-JS-Hooks/src/event-manager.js',
|
'wp-js-hooks': 'WP-JS-Hooks/src/event-manager.js',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
resolveLoader: {
|
||||||
|
alias: {
|
||||||
|
// replace 'amd-inject-loader' with a wrapper fixed for Webpack 4
|
||||||
|
'amd-inject-loader': path.join(__dirname, 'assets/js/src/amd-inject-loader-fixed.js'),
|
||||||
|
}
|
||||||
|
},
|
||||||
externals: {
|
externals: {
|
||||||
'jquery': 'jQuery',
|
'jquery': 'jQuery',
|
||||||
'tinymce': 'tinymce',
|
'tinymce': 'tinymce',
|
||||||
@@ -370,25 +408,15 @@ var testConfig = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = _.map([adminConfig, publicConfig, migratorConfig, testConfig], function (config) {
|
module.exports = [adminConfig, publicConfig, migratorConfig, testConfig].map((config) => {
|
||||||
if (config.name !== 'test') {
|
if (config.name !== 'test') {
|
||||||
config.plugins = config.plugins || [];
|
config.plugins = config.plugins || [];
|
||||||
if (PRODUCTION_ENV) {
|
|
||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new webpackUglifyJsPlugin({
|
|
||||||
mangle: false,
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env.NODE_ENV': JSON.stringify('production')
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
config.plugins.push(
|
|
||||||
new webpackMD5HashPlugin(),
|
|
||||||
new webpackManifestPlugin({
|
new webpackManifestPlugin({
|
||||||
cache: manifestCache
|
// create single manifest file for all Webpack configs
|
||||||
|
seed: manifestSeed,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _.extend({}, baseConfig, config);
|
return Object.assign({}, baseConfig, config);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user