Skip to content

Instantly share code, notes, and snippets.

@jonathan-s
Last active April 15, 2020 07:38
Show Gist options
  • Save jonathan-s/caabedcaae0226ee2099035a0878c533 to your computer and use it in GitHub Desktop.
Save jonathan-s/caabedcaae0226ee2099035a0878c533 to your computer and use it in GitHub Desktop.
The most minimal setup for webpack that loads javascript from a directory and spits out the compiled version of that javascript. Probably needs babel as well.
{
"name": "foxflash-backend",
"version": "1.0.0",
"description": "Generate javascript and css",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
},
"repository": {
"type": "git"
},
"author": "Jonathan S",
"license": "ISC",
"dependencies": {
"fs": "0.0.1-security",
"node-sass": "^4.12.0",
"path": "^0.12.7",
"webpack": "^4.42.1"
},
"devDependencies": {
"webpack-cli": "^3.3.11"
}
}
# so that the js files can be accessed as static files.
STATICFILES_DIRS = [
('js', '{}/frontend/dist/js/'.format(BASE_DIR)),
]
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const rootPath = __dirname;
const entryPath = 'frontend/src/js/';
const entryFiles = fs.readdirSync(path.join(rootPath,entryPath));
let entryObj = {};
entryFiles.forEach(function(file){
var fileName = file.split('.')[0];
entryObj[fileName] = `./${entryPath}${file}`;
});
const config = {
mode: process.env.NODE_ENV,
entry: entryObj,
output: {
path: __dirname + '/frontend/dist/js',
filename: '[name].js'
}
}
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment