Last active
June 8, 2016 09:07
-
-
Save johnathan-sewell/e6d5afab19ac2517471fb66c392b372d to your computer and use it in GitHub Desktop.
Webpack loader for generating configuration from script variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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