3 // TODO: this should be broken up into `dev` and `prod`
4 // configuration variants
6 var webpack = require('webpack')
7 var getConfig = require('hjs-webpack')
8 var path = require('path')
10 // Set base path to JS and CSS files when
11 // required by other files
13 let outPath = 'public'
14 if (process.env.NODE_ENV === 'production') {
15 publicPath = ( process.env.MODE === 'electron' )? '' : '/dashboard/'
17 outPath = 'node_modules/dashboard-dlls'
20 // Creates a webpack config object. The
21 // object can be extended by accessing
23 var config = getConfig({
24 // entry point for the app
27 // Name or full path of output directory
28 // commonly named `www` or `public`. This
29 // is where your fully static site should
30 // end up for simple deployment.
37 // This will destroy and re-create your
38 // `out` folder before building so you always
39 // get a fresh folder. Usually you want this
40 // but since it's destructive we make it
42 clearBeforeBuild: true,
44 html: function (context) {
46 'index.html': context.defaultTemplate({
47 publicPath: publicPath,
48 head: process.env.NODE_ENV !== 'production' ? '<script data-dll="true" src="/dependencies.dll.js"></script>' : '',
53 // Proxy API requests to local core server
58 target: process.env.PROXY_API_HOST || 'http://localhost:1999',
67 // Customize loader configuration
68 let loaders = config.module.loaders
70 for (let item of loaders) {
71 // Enable CSS module support
72 if (item.loader && item.loader.indexOf('css-loader') > 0) {
73 item.loader = item.loader.replace('css-loader','css-loader?module&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]')
75 if ('.scss'.match(item.test) != null) {
76 item.loader = item.loader.replace('sass-loader','sass-loader!sass-resources-loader')
79 // Enable babel-loader caching
80 if (item.loader == 'babel-loader') {
81 item.loader = 'babel-loader?cacheDirectory'
85 config.module.loaders = loaders
86 config.sassResources = './static/styles/resources.scss'
88 // Configure node modules which may or
89 // may not be present in the browser.
99 path.resolve('./src'),
100 path.resolve('./static'),
102 extensions: [ '', '.js', '.jsx' ]
105 // module.noParse disables parsing for
106 // matched files. Used here to bypass
107 // issues with an AMD configured module.
108 config.module.noParse = /node_modules\/json-schema\/lib\/validate\.js/
110 // Import specified env vars in packaged source
111 config.plugins.push(new webpack.DefinePlugin({
112 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
113 'process.env.API_URL': JSON.stringify(process.env.API_URL),
114 'process.env.MODE': JSON.stringify(process.env.MODE),
115 'process.env.PROXY_API_HOST': JSON.stringify(process.env.PROXY_API_HOST),
116 'process.env.TESTNET_INFO_URL': JSON.stringify(process.env.TESTNET_INFO_URL),
117 'process.env.TESTNET_GENERATOR_URL': JSON.stringify(process.env.TESTNET_GENERATOR_URL),
120 // Enable babel-polyfill
121 config.entry.push('babel-polyfill')
123 config.output.publicPath = publicPath
125 if (process.env.NODE_ENV !== 'production') {
126 // Support source maps for Babel
127 config.devtool = 'eval-cheap-module-source-map'
130 config.plugins.push(new webpack.DllReferencePlugin({
131 context: process.cwd(),
132 manifest: require(path.resolve(process.cwd(), 'node_modules/dashboard-dlls/manifest.json')),
136 module.exports = config