github.com/shyftnetwork/go-empyrean@v1.8.3-0.20191127201940-fbfca9338f04/shyftBlockExplorerUI/config/webpack.config.dev.js (about) 1 'use strict'; 2 3 const autoprefixer = require('autoprefixer'); 4 const path = require('path'); 5 const webpack = require('webpack'); 6 const HtmlWebpackPlugin = require('html-webpack-plugin'); 7 const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); 8 const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); 9 const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); 10 const eslintFormatter = require('react-dev-utils/eslintFormatter'); 11 const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); 12 const getClientEnvironment = require('./env'); 13 const paths = require('./paths'); 14 15 // Webpack uses `publicPath` to determine where the app is being served from. 16 // In development, we always serve from the root. This makes config easier. 17 const publicPath = '/'; 18 // `publicUrl` is just like `publicPath`, but we will provide it to our app 19 // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. 20 // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz. 21 const publicUrl = ''; 22 // Get environment variables to inject into our app. 23 const env = getClientEnvironment(publicUrl); 24 25 // This is the development configuration. 26 // It is focused on developer experience and fast rebuilds. 27 // The production configuration is different and lives in a separate file. 28 module.exports = { 29 // You may want 'eval' instead if you prefer to see the compiled output in DevTools. 30 // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343. 31 devtool: 'cheap-module-source-map', 32 // These are the "entry points" to our application. 33 // This means they will be the "root" imports that are included in JS bundle. 34 // The first two entry points enable "hot" CSS and auto-refreshes for JS. 35 entry: [ 36 // We ship a few polyfills by default: 37 require.resolve('./polyfills'), 38 // Include an alternative client for WebpackDevServer. A client's job is to 39 // connect to WebpackDevServer by a socket and get notified about changes. 40 // When you save a file, the client will either apply hot updates (in case 41 // of CSS changes), or refresh the page (in case of JS changes). When you 42 // make a syntax error, this client will display a syntax error overlay. 43 // Note: instead of the default WebpackDevServer client, we use a custom one 44 // to bring better experience for Create React App users. You can replace 45 // the line below with these two lines if you prefer the stock client: 46 // require.resolve('webpack-dev-server/client') + '?/', 47 // require.resolve('webpack/hot/dev-server'), 48 require.resolve('react-dev-utils/webpackHotDevClient'), 49 // Finally, this is your app's code: 50 paths.appIndexJs, 51 // We include the app code last so that if there is a runtime error during 52 // initialization, it doesn't blow up the WebpackDevServer client, and 53 // changing JS code would still trigger a refresh. 54 ], 55 output: { 56 // Add /* filename */ comments to generated require()s in the output. 57 pathinfo: true, 58 // This does not produce a real file. It's just the virtual path that is 59 // served by WebpackDevServer in development. This is the JS bundle 60 // containing code from all our entry points, and the Webpack runtime. 61 filename: 'static/js/bundle.js', 62 // There are also additional JS chunk files if you use code splitting. 63 chunkFilename: 'static/js/[name].chunk.js', 64 // This is the URL that app is served from. We use "/" in development. 65 publicPath: publicPath, 66 // Point sourcemap entries to original disk location (format as URL on Windows) 67 devtoolModuleFilenameTemplate: info => 68 path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), 69 }, 70 resolve: { 71 // This allows you to set a fallback for where Webpack should look for modules. 72 // We placed these paths second because we want `node_modules` to "win" 73 // if there are any conflicts. This matches Node resolution mechanism. 74 // https://github.com/facebookincubator/create-react-app/issues/253 75 modules: ['node_modules', paths.appNodeModules].concat( 76 // It is guaranteed to exist because we tweak it in `env.js` 77 process.env.NODE_PATH.split(path.delimiter).filter(Boolean) 78 ), 79 // These are the reasonable defaults supported by the Node ecosystem. 80 // We also include JSX as a common component filename extension to support 81 // some tools, although we do not recommend using it, see: 82 // https://github.com/facebookincubator/create-react-app/issues/290 83 // `web` extension prefixes have been added for better support 84 // for React Native Web. 85 extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'], 86 alias: { 87 88 // Support React Native Web 89 // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 90 'react-native': 'react-native-web', 91 }, 92 plugins: [ 93 // Prevents users from importing files from outside of src/ (or node_modules/). 94 // This often causes confusion because we only process files within src/ with babel. 95 // To fix this, we prevent you from importing files out of src/ -- if you'd like to, 96 // please link the files into your node_modules/ and let module-resolution kick in. 97 // Make sure your source files are compiled, as they will not be processed in any way. 98 new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), 99 ], 100 }, 101 module: { 102 strictExportPresence: true, 103 rules: [ 104 // TODO: Disable require.ensure as it's not a standard language feature. 105 // We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176. 106 // { parser: { requireEnsure: false } }, 107 108 // First, run the linter. 109 // It's important to do this before Babel processes the JS. 110 { 111 test: /\.(js|jsx|mjs)$/, 112 enforce: 'pre', 113 use: [ 114 { 115 options: { 116 formatter: eslintFormatter, 117 eslintPath: require.resolve('eslint'), 118 119 }, 120 loader: require.resolve('eslint-loader'), 121 }, 122 ], 123 include: paths.appSrc, 124 }, 125 { 126 // "oneOf" will traverse all following loaders until one will 127 // match the requirements. When no loader matches it will fall 128 // back to the "file" loader at the end of the loader list. 129 oneOf: [ 130 // "url" loader works like "file" loader except that it embeds assets 131 // smaller than specified limit in bytes as data URLs to avoid requests. 132 // A missing `test` is equivalent to a match. 133 { 134 test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], 135 loader: require.resolve('url-loader'), 136 options: { 137 limit: 10000, 138 name: 'static/media/[name].[hash:8].[ext]', 139 }, 140 }, 141 // Process JS with Babel. 142 { 143 test: /\.(js|jsx|mjs)$/, 144 include: paths.appSrc, 145 loader: require.resolve('babel-loader'), 146 options: { 147 148 // This is a feature of `babel-loader` for webpack (not Babel itself). 149 // It enables caching results in ./node_modules/.cache/babel-loader/ 150 // directory for faster rebuilds. 151 cacheDirectory: true, 152 }, 153 }, 154 // "postcss" loader applies autoprefixer to our CSS. 155 // "css" loader resolves paths in CSS and adds assets as dependencies. 156 // "style" loader turns CSS into JS modules that inject <style> tags. 157 // In production, we use a plugin to extract that CSS to a file, but 158 // in development "style" loader enables hot editing of CSS. 159 { 160 test: /\.css$/, 161 use: [ 162 require.resolve('style-loader'), 163 { 164 loader: require.resolve('css-loader'), 165 options: { 166 importLoaders: 1, 167 modules: true, 168 localIdentName: '[name]__[local]__[hash:base64:5]' 169 }, 170 }, 171 { 172 loader: require.resolve('postcss-loader'), 173 options: { 174 // Necessary for external CSS imports to work 175 // https://github.com/facebookincubator/create-react-app/issues/2677 176 ident: 'postcss', 177 plugins: () => [ 178 require('postcss-flexbugs-fixes'), 179 autoprefixer({ 180 browsers: [ 181 '>1%', 182 'last 4 versions', 183 'Firefox ESR', 184 'not ie < 9', // React doesn't support IE8 anyway 185 ], 186 flexbox: 'no-2009', 187 }), 188 ], 189 }, 190 }, 191 ], 192 }, 193 // "file" loader makes sure those assets get served by WebpackDevServer. 194 // When you `import` an asset, you get its (virtual) filename. 195 // In production, they would get copied to the `build` folder. 196 // This loader doesn't use a "test" so it will catch all modules 197 // that fall through the other loaders. 198 { 199 // Exclude `js` files to keep "css" loader working as it injects 200 // its runtime that would otherwise processed through "file" loader. 201 // Also exclude `html` and `json` extensions so they get processed 202 // by webpacks internal loaders. 203 exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/], 204 loader: require.resolve('file-loader'), 205 options: { 206 name: 'static/media/[name].[hash:8].[ext]', 207 }, 208 }, 209 ], 210 }, 211 // ** STOP ** Are you adding a new loader? 212 // Make sure to add the new loader(s) before the "file" loader. 213 ], 214 }, 215 plugins: [ 216 // Makes some environment variables available in index.html. 217 // The public URL is available as %PUBLIC_URL% in index.html, e.g.: 218 // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> 219 // In development, this will be an empty string. 220 new InterpolateHtmlPlugin(env.raw), 221 // Generates an `index.html` file with the <script> injected. 222 new HtmlWebpackPlugin({ 223 inject: true, 224 template: paths.appHtml, 225 }), 226 // Add module names to factory functions so they appear in browser profiler. 227 new webpack.NamedModulesPlugin(), 228 // Makes some environment variables available to the JS code, for example: 229 // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`. 230 new webpack.DefinePlugin(env.stringified), 231 // This is necessary to emit hot updates (currently CSS only): 232 new webpack.HotModuleReplacementPlugin(), 233 // Watcher doesn't work well if you mistype casing in a path so we use 234 // a plugin that prints an error when you attempt to do this. 235 // See https://github.com/facebookincubator/create-react-app/issues/240 236 new CaseSensitivePathsPlugin(), 237 // If you require a missing module and then `npm install` it, you still have 238 // to restart the development server for Webpack to discover it. This plugin 239 // makes the discovery automatic so you don't have to restart. 240 // See https://github.com/facebookincubator/create-react-app/issues/186 241 new WatchMissingNodeModulesPlugin(paths.appNodeModules), 242 // Moment.js is an extremely popular library that bundles large locale files 243 // by default due to how Webpack interprets its code. This is a practical 244 // solution that requires the user to opt into importing specific locales. 245 // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack 246 // You can remove this if you don't use Moment.js: 247 new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), 248 ], 249 // Some libraries import Node modules but don't use them in the browser. 250 // Tell Webpack to provide empty mocks for them so importing them works. 251 node: { 252 dgram: 'empty', 253 fs: 'empty', 254 net: 'empty', 255 tls: 'empty', 256 child_process: 'empty', 257 }, 258 // Turn off performance hints during development because we don't do any 259 // splitting or minification in interest of speed. These warnings become 260 // cumbersome. 261 performance: { 262 hints: false, 263 }, 264 };