2018-03-21 12:08:18 +00:00
|
|
|
const fs = require('fs')
|
2018-01-12 11:41:02 +00:00
|
|
|
const path = require('path')
|
2018-05-11 14:34:22 +00:00
|
|
|
const webpack = require('webpack')
|
2018-01-12 11:41:02 +00:00
|
|
|
|
2018-03-21 12:08:18 +00:00
|
|
|
const MODULES_PATH = path.join(__dirname, '/modules')
|
2018-05-11 14:34:22 +00:00
|
|
|
const webpackENV = process.env.WEBPACK_ENV || 'development'
|
2018-03-21 12:08:18 +00:00
|
|
|
|
|
|
|
// Generate a hash of entry points, including modules
|
|
|
|
const entryPoints = {}
|
|
|
|
if (fs.existsSync(MODULES_PATH)) {
|
|
|
|
fs.readdirSync(MODULES_PATH).reduce((acc, module) => {
|
|
|
|
const entryPath = path.join(MODULES_PATH, module, '/public/es/index.js')
|
|
|
|
if (fs.existsSync(entryPath)) {
|
|
|
|
acc[module] = entryPath
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
}, entryPoints)
|
|
|
|
}
|
|
|
|
|
2018-03-27 11:30:40 +00:00
|
|
|
// If no entry points are found, silently exit
|
|
|
|
if (!Object.keys(entryPoints).length) {
|
|
|
|
console.warn('No entry points found, exiting')
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
|
2018-01-12 11:41:02 +00:00
|
|
|
module.exports = {
|
2018-01-12 12:34:04 +00:00
|
|
|
// Defines the "entry point(s)" for the application - i.e. the file which
|
2018-01-12 11:41:02 +00:00
|
|
|
// bootstraps the application
|
2018-03-21 12:08:18 +00:00
|
|
|
entry: entryPoints,
|
2018-01-12 11:41:02 +00:00
|
|
|
|
|
|
|
// Define where and how the bundle will be output to disk
|
|
|
|
// Note: webpack-dev-server does not write the bundle to disk, instead it is
|
|
|
|
// kept in memory for speed
|
|
|
|
output: {
|
2018-01-12 12:34:04 +00:00
|
|
|
path: path.join(__dirname, '/public/js/es'),
|
2018-01-12 11:41:02 +00:00
|
|
|
|
|
|
|
filename: '[name].js',
|
|
|
|
|
|
|
|
// Output as UMD bundle (allows main JS to import with CJS, AMD or global
|
|
|
|
// style code bundles
|
|
|
|
libraryTarget: 'umd',
|
|
|
|
// Name the exported variable from output bundle
|
|
|
|
library: ['Frontend', '[name]']
|
|
|
|
},
|
|
|
|
|
|
|
|
// Define how file types are handled by webpack
|
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
// Pass application JS files through babel-loader, compiling to ES5
|
2018-02-22 19:27:25 +00:00
|
|
|
test: /\.js$/,
|
2018-01-12 11:41:02 +00:00
|
|
|
// Only compile application files (dependencies are in ES5 already)
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2018-02-21 17:07:34 +00:00
|
|
|
presets: [
|
2018-04-10 09:01:10 +00:00
|
|
|
'react',
|
2018-02-21 17:07:34 +00:00
|
|
|
['env', { modules: false }]
|
|
|
|
],
|
2018-01-12 11:41:02 +00:00
|
|
|
// Configure babel-loader to cache compiled output so that subsequent
|
|
|
|
// compile runs are much faster
|
|
|
|
cacheDirectory: true
|
|
|
|
}
|
|
|
|
}]
|
2018-05-11 08:57:36 +00:00
|
|
|
},
|
|
|
|
{
|
2018-05-15 08:44:57 +00:00
|
|
|
// These options are necesary for handlebars to have access to helper
|
|
|
|
// methods
|
2018-05-11 08:57:36 +00:00
|
|
|
test: /\.handlebars$/,
|
|
|
|
loader: "handlebars-loader",
|
|
|
|
options: {
|
|
|
|
compat: true,
|
|
|
|
knownHelpersOnly: false,
|
|
|
|
runtimePath: 'handlebars/runtime',
|
|
|
|
}
|
2018-01-12 11:41:02 +00:00
|
|
|
}]
|
|
|
|
},
|
2018-05-11 08:57:36 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
2018-05-15 08:44:57 +00:00
|
|
|
// makes handlerbars globally accessible to backbone
|
2018-05-11 08:57:36 +00:00
|
|
|
handlebars: 'handlebars/dist/handlebars.min.js',
|
|
|
|
jquery: path.join(__dirname, 'node_modules/jquery/dist/jquery'),
|
|
|
|
}
|
|
|
|
},
|
2018-05-11 14:34:22 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
// Swaps out checks for NODE_ENV with the env. This is used by various
|
|
|
|
// libs to enable dev-only features. These checks then become something
|
|
|
|
// like `if ('production' == 'production')`. Minification will then strip
|
|
|
|
// the dev-only code from the bundle
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(webpackENV)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
]
|
2018-03-29 15:15:53 +00:00
|
|
|
}
|