Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Last active June 8, 2016 09:07
Show Gist options
  • Save johnathan-sewell/e6d5afab19ac2517471fb66c392b372d to your computer and use it in GitHub Desktop.
Save johnathan-sewell/e6d5afab19ac2517471fb66c392b372d to your computer and use it in GitHub Desktop.
Webpack loader for generating configuration from script variables
// Config loader reads command line args (in a build script) and outputs a new config file
// this approach was used to build different versions of a Chrome extension
//configLoader
const replaceCommandLineArgs = require('./replaceCommandLineArgs');
const configTemplate = require('./appConfig');
module.exports = function() {
const config = replaceCommandLineArgs(configTemplate);
return `module.exports = ${JSON.stringify(config)};`;
};
//appConfig.js:
// module.exports = {
// socketHost: {
// defaultValue: 'http://127.0.0.1',
// cmdLineArgName: 'socket-host'
// },
// socketPort: {
// defaultValue: 3000,
// cmdLineArgName: 'socket-port'
// }
// };
//webpack config:
// module.exports = {
// entry: {
// ...
// },
// output: {
// ...
// },
// module: {
// loaders: [{
// test: /\.js$/,
// include: [
// path.resolve(__dirname, 'js'),
// path.resolve(__dirname, 'popup')
// ],
// loader: 'babel-loader'
// }, {
// test: /appConfig\.js$/,
// loader: __dirname + '/js/config/configLoader.js'
// }]
// },
// devtool: 'source-map'
// };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment