generate webpack entry points for pages directory automatically

This commit is contained in:
Mike Greiling 2018-01-15 11:50:26 -06:00
parent a24e58271a
commit 900124810c
No known key found for this signature in database
GPG key ID: 0303DF507FA67596
3 changed files with 14 additions and 1 deletions

View file

@ -3,6 +3,7 @@
var crypto = require('crypto'); var crypto = require('crypto');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var glob = require('glob');
var webpack = require('webpack'); var webpack = require('webpack');
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
var CopyWebpackPlugin = require('copy-webpack-plugin'); var CopyWebpackPlugin = require('copy-webpack-plugin');
@ -20,6 +21,15 @@ var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false';
var WEBPACK_REPORT = process.env.WEBPACK_REPORT; var WEBPACK_REPORT = process.env.WEBPACK_REPORT;
var NO_COMPRESSION = process.env.NO_COMPRESSION; var NO_COMPRESSION = process.env.NO_COMPRESSION;
// generate automatic entry points
var autoEntries = {};
var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') });
pageEntries.forEach(( path ) => {
let chunkName = path.replace(/\/index\.js$/, '').replace(/\//g, '.');
autoEntries[chunkName] = './' + path;
});
var config = { var config = {
// because sqljs requires fs. // because sqljs requires fs.
node: { node: {
@ -301,6 +311,8 @@ var config = {
} }
} }
config.entry = Object.assign({}, autoEntries, config.entry);
if (IS_PRODUCTION) { if (IS_PRODUCTION) {
config.devtool = 'source-map'; config.devtool = 'source-map';
config.plugins.push( config.plugins.push(

View file

@ -47,6 +47,7 @@
"exports-loader": "^0.6.4", "exports-loader": "^0.6.4",
"file-loader": "^0.11.1", "file-loader": "^0.11.1",
"fuzzaldrin-plus": "^0.5.0", "fuzzaldrin-plus": "^0.5.0",
"glob": "^7.1.2",
"imports-loader": "^0.7.1", "imports-loader": "^0.7.1",
"jed": "^1.1.1", "jed": "^1.1.1",
"jquery": "^2.2.4", "jquery": "^2.2.4",

View file

@ -3322,7 +3322,7 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1:
once "^1.3.0" once "^1.3.0"
path-is-absolute "^1.0.0" path-is-absolute "^1.0.0"
glob@^7.1.0, glob@~7.1.2: glob@^7.1.0, glob@^7.1.2, glob@~7.1.2:
version "7.1.2" version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies: dependencies: