generate webpack entry points for pages directory automatically
This commit is contained in:
parent
a24e58271a
commit
900124810c
3 changed files with 14 additions and 1 deletions
|
@ -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(
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue