2017-02-10 16:18:42 +01:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2016-02-24 11:44:14 +01:00
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
// Generates a path to an entry file to be compiled by Webpack.
|
|
|
|
const getEntryPath = (app, filename) => path.resolve('wagtail', app, 'static_src', app, 'app', filename);
|
|
|
|
// Generates a path to the output bundle to be loaded in the browser.
|
|
|
|
const getOutputPath = (app, filename) => path.join('wagtail', app, 'static', app, 'js', filename);
|
2016-02-24 11:44:14 +01:00
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
const isVendorModule = (module) => {
|
|
|
|
const res = module.resource;
|
|
|
|
return res && res.indexOf('node_modules') >= 0 && res.match(/\.js$/);
|
|
|
|
};
|
2016-02-24 11:44:14 +01:00
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
module.exports = function exports() {
|
|
|
|
const entry = {
|
|
|
|
// Create a vendor chunk that will contain polyfills, and all third-party dependencies.
|
2017-06-07 15:18:44 +02:00
|
|
|
vendor: [
|
|
|
|
'./client/src/utils/polyfills.js',
|
|
|
|
],
|
2017-02-12 16:29:56 +01:00
|
|
|
};
|
2016-02-24 11:44:14 +01:00
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
entry[getOutputPath('wagtailadmin', 'wagtailadmin')] = getEntryPath('wagtailadmin', 'wagtailadmin.entry.js');
|
2016-02-24 11:44:14 +01:00
|
|
|
|
|
|
|
return {
|
2017-02-12 16:29:56 +01:00
|
|
|
entry: entry,
|
2016-02-24 11:44:14 +01:00
|
|
|
output: {
|
2017-06-07 11:39:24 +02:00
|
|
|
path: path.resolve('.'),
|
2016-02-24 11:44:14 +01:00
|
|
|
filename: '[name].js',
|
|
|
|
publicPath: '/static/js/'
|
|
|
|
},
|
|
|
|
plugins: [
|
2017-02-12 16:29:56 +01:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor',
|
|
|
|
filename: getOutputPath('wagtailadmin', '[name].js'),
|
|
|
|
minChunks: isVendorModule,
|
|
|
|
}),
|
2016-02-24 11:44:14 +01:00
|
|
|
],
|
2017-02-12 16:29:56 +01:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'wagtail-client': path.resolve('.', 'client'),
|
|
|
|
},
|
|
|
|
},
|
2016-02-24 11:44:14 +01:00
|
|
|
module: {
|
2017-06-07 11:39:24 +02:00
|
|
|
rules: [
|
2016-02-24 11:44:14 +01:00
|
|
|
{
|
2017-02-10 16:18:42 +01:00
|
|
|
test: /\.js$/,
|
2017-06-07 11:39:24 +02:00
|
|
|
loader: 'babel-loader',
|
2017-05-28 20:49:05 +02:00
|
|
|
exclude: /node_modules/,
|
2016-02-24 11:44:14 +01:00
|
|
|
},
|
|
|
|
]
|
2017-02-12 16:29:56 +01:00
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
// Add chunk information (setting this to `false` allows for a less verbose output)
|
|
|
|
chunks: false,
|
|
|
|
// Add the hash of the compilation
|
|
|
|
hash: false,
|
|
|
|
// `webpack --colors` equivalent
|
|
|
|
colors: true,
|
|
|
|
// Add information about the reasons why modules are included
|
|
|
|
reasons: false,
|
|
|
|
// Add webpack version information
|
|
|
|
version: false,
|
2017-06-07 15:29:58 +02:00
|
|
|
// Set the maximum number of modules to be shown
|
|
|
|
maxModules: 0,
|
2017-02-12 16:29:56 +01:00
|
|
|
},
|
2017-06-07 15:21:12 +02:00
|
|
|
// Some libraries import Node modules but don't use them in the browser.
|
|
|
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
net: 'empty',
|
|
|
|
tls: 'empty',
|
|
|
|
},
|
2016-02-24 11:44:14 +01:00
|
|
|
};
|
|
|
|
};
|