Adds manifest to JS assets

Adds conditional assets caching based on environment
This commit is contained in:
Vlad
2017-06-14 22:40:21 -04:00
parent 64dbf158a4
commit 167fb86927
2 changed files with 59 additions and 26 deletions

View File

@@ -38,6 +38,7 @@
"amd-inject-loader": "~0.5.0", "amd-inject-loader": "~0.5.0",
"babel-core": "^5.8.22", "babel-core": "^5.8.22",
"babel-loader": "^5.3.2", "babel-loader": "^5.3.2",
"clean-webpack-plugin": "^0.1.16",
"chai": "2.2.0", "chai": "2.2.0",
"chai-jq": "0.0.8", "chai-jq": "0.0.8",
"eslint": "^3.19.0", "eslint": "^3.19.0",
@@ -56,6 +57,8 @@
"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": "1.11.0" "webpack": "1.11.0",
"webpack-manifest-plugin": "^1.1.0",
"webpack-md5-hash": "0.0.5"
} }
} }

View File

@@ -1,11 +1,16 @@
var webpack = require('webpack'), var webpack = require('webpack');
_ = require('underscore'), var webpackManifestPlugin = require('webpack-manifest-plugin');
path = require('path'), var webpackMD5HashPlugin = require('webpack-md5-hash');
baseConfig = {}, var webpackCleanPlugin = require('clean-webpack-plugin');
config = [], var _ = require('underscore');
globalPrefix = 'MailPoetLib'; var path = require('path');
var globalPrefix = 'MailPoetLib';
var PRODUCTION_ENV = process.env.NODE_ENV === 'production';
var manifestCache = {};
baseConfig = { // Base config
var baseConfig = {
cache: true,
context: __dirname, context: __dirname,
watch: { watch: {
aggregateTimeout: 300, aggregateTimeout: 300,
@@ -13,7 +18,8 @@ baseConfig = {
}, },
output: { output: {
path: './assets/js', path: './assets/js',
filename: '[name].js', filename: (PRODUCTION_ENV) ? '[name].[chunkhash:8].js' : '[name].js',
chunkFilename: (PRODUCTION_ENV) ? '[name].[chunkhash:8].chunk.js' : '[name].chunk.js'
}, },
resolve: { resolve: {
modulesDirectories: [ modulesDirectories: [
@@ -38,6 +44,11 @@ baseConfig = {
node: { node: {
fs: 'empty' fs: 'empty'
}, },
plugins: [
new webpackCleanPlugin([
'./assets/js/*.*',
])
],
module: { module: {
loaders: [ loaders: [
{ {
@@ -120,8 +131,8 @@ baseConfig = {
} }
}; };
// Admin // Admin config
config.push(_.extend({}, baseConfig, { var adminConfig = {
name: 'admin', name: 'admin',
entry: { entry: {
vendor: [ vendor: [
@@ -213,17 +224,26 @@ config.push(_.extend({}, baseConfig, {
] ]
}, },
plugins: [ plugins: [
new webpack.optimize.CommonsChunkPlugin('admin_vendor', 'admin_vendor.js', ['admin_vendor', 'admin']), new webpack.optimize.CommonsChunkPlugin({
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js') name: 'admin_vendor',
fileName: 'admin_vendor.js',
chunks: ['admin_vendor', 'admin'],
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
fileName: 'vendor.js',
minChunks: Infinity
})
], ],
externals: { externals: {
'jquery': 'jQuery', 'jquery': 'jQuery',
'tinymce': 'tinymce' 'tinymce': 'tinymce'
} }
})); };
// Public // Public config
config.push(_.extend({}, baseConfig, { var publicConfig = {
name: 'public', name: 'public',
entry: { entry: {
public: [ public: [
@@ -237,10 +257,10 @@ config.push(_.extend({}, baseConfig, {
externals: { externals: {
'jquery': 'jQuery' 'jquery': 'jQuery'
} }
})); };
// mp2migrator // Migrator config
config.push(_.extend({}, baseConfig, { var migratorConfig = {
name: 'mp2migrator', name: 'mp2migrator',
entry: { entry: {
mp2migrator: [ mp2migrator: [
@@ -251,10 +271,9 @@ config.push(_.extend({}, baseConfig, {
'jquery': 'jQuery', 'jquery': 'jQuery',
'mailpoet': 'MailPoet' 'mailpoet': 'MailPoet'
} }
})); };
// Test config
// Test var testConfig = {
config.push(_.extend({}, baseConfig, {
name: 'test', name: 'test',
entry: { entry: {
vendor: ['handlebars', 'handlebars_helpers'], vendor: ['handlebars', 'handlebars_helpers'],
@@ -348,6 +367,17 @@ config.push(_.extend({}, baseConfig, {
'interact': 'interact', 'interact': 'interact',
'spectrum': 'spectrum', 'spectrum': 'spectrum',
} }
})); };
module.exports = config; module.exports = _.map([adminConfig, publicConfig, migratorConfig, testConfig], function (config) {
if (config.name !== 'test') {
config.plugins = config.plugins || [];
config.plugins.push(
new webpackMD5HashPlugin(),
new webpackManifestPlugin({
cache: manifestCache
})
);
}
return _.extend({}, baseConfig, config);
});