OSDN Git Service

fixed the value error
[bytom/bytom-electron.git] / webpack / webpack.app.js
1 /*eslint-env node*/
2
3 // TODO: this should be broken up into `dev` and `prod`
4 // configuration variants
5
6 var webpack = require('webpack')
7 var getConfig = require('hjs-webpack')
8 var path = require('path')
9
10 // Set base path to JS and CSS files when
11 // required by other files
12 let publicPath = '/'
13 let outPath = 'public'
14 if (process.env.NODE_ENV === 'production') {
15   publicPath = '/dashboard/'
16 } else {
17   outPath = 'node_modules/dashboard-dlls'
18 }
19
20 // Creates a webpack config object. The
21 // object can be extended by accessing
22 // its properties.
23 var config = getConfig({
24   // entry point for the app
25   in: 'src/app.js',
26
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.
31   out: outPath,
32
33   output: {
34     hash: true
35   },
36
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
41   // false by default
42   clearBeforeBuild: true,
43
44   html: function (context) {
45     return {
46       'index.html': context.defaultTemplate({
47         publicPath: publicPath,
48         head: process.env.NODE_ENV !== 'production' ? '<script data-dll="true" src="/dependencies.dll.js"></script>' : '',
49       })
50     }
51   },
52
53   // Proxy API requests to local core server
54   devServer: {
55     proxy: {
56       context: '/api',
57       options: {
58         target: process.env.PROXY_API_HOST || 'http://localhost:1999',
59         pathRewrite: {
60           '^/api': ''
61         }
62       }
63     }
64   }
65 })
66
67 // Customize loader configuration
68 let loaders = config.module.loaders
69
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]')
74   }
75   if ('.scss'.match(item.test) != null) {
76     item.loader = item.loader.replace('sass-loader','sass-loader!sass-resources-loader')
77   }
78
79   // Enable babel-loader caching
80   if (item.loader == 'babel-loader') {
81     item.loader = 'babel-loader?cacheDirectory'
82   }
83 }
84
85 config.module.loaders = loaders
86 config.sassResources = './static/styles/resources.scss'
87
88 // Configure node modules which may or
89 // may not be present in the browser.
90 config.node = {
91   console: true,
92   fs: 'empty',
93   net: 'empty',
94   tls: 'empty'
95 }
96
97 config.resolve = {
98   root: [
99     path.resolve('./src'),
100     path.resolve('./static'),
101   ],
102   extensions: [ '', '.js', '.jsx' ]
103 }
104
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/
109
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.PROXY_API_HOST': JSON.stringify(process.env.PROXY_API_HOST),
115   'process.env.TESTNET_INFO_URL': JSON.stringify(process.env.TESTNET_INFO_URL),
116   'process.env.TESTNET_GENERATOR_URL': JSON.stringify(process.env.TESTNET_GENERATOR_URL),
117 }))
118
119 // Enable babel-polyfill
120 config.entry.push('babel-polyfill')
121
122 config.output.publicPath = publicPath
123
124 if (process.env.NODE_ENV !== 'production') {
125   // Support source maps for Babel
126   config.devtool = 'eval-cheap-module-source-map'
127
128   // Use DLL
129   config.plugins.push(new webpack.DllReferencePlugin({
130     context: process.cwd(),
131     manifest: require(path.resolve(process.cwd(), 'node_modules/dashboard-dlls/manifest.json')),
132   }))
133 }
134
135 module.exports = config