UNPKG

10.9 kBJavaScriptView Raw
1// @remove-on-eject-begin
2/**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the root directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
9 */
10// @remove-on-eject-end
11'use strict';
12
13var autoprefixer = require('autoprefixer');
14var webpack = require('webpack');
15var ManifestPlugin = require('webpack-manifest-plugin');
16var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
17var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
18var prometheus = require('./prometheus');
19var getClientEnvironment = require('./env');
20var paths = require('./paths');
21
22// @remove-on-eject-begin
23// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
24var path = require('path');
25// @remove-on-eject-end
26
27// Webpack uses `publicPath` to determine where the app is being served from.
28// In development, we always serve from the root. This makes config easier.
29var publicPath = '/';
30// `publicUrl` is just like `publicPath`, but we will provide it to our app
31// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
32// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
33var publicUrl = '';
34// Get environment variables to inject into our app.
35var env = getClientEnvironment(publicUrl);
36
37// This is the development configuration.
38// It is focused on developer experience and fast rebuilds.
39// The production configuration is different and lives in a separate file.
40module.exports = {
41 // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
42 // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
43 devtool: 'cheap-module-source-map',
44 // These are the "entry points" to our application.
45 // This means they will be the "root" imports that are included in JS bundle.
46 // The first two entry points enable "hot" CSS and auto-refreshes for JS.
47 entry: [
48 // Include an alternative client for WebpackDevServer. A client's job is to
49 // connect to WebpackDevServer by a socket and get notified about changes.
50 // When you save a file, the client will either apply hot updates (in case
51 // of CSS changes), or refresh the page (in case of JS changes). When you
52 // make a syntax error, this client will display a syntax error overlay.
53 // Note: instead of the default WebpackDevServer client, we use a custom one
54 // to bring better experience for Create React App users. You can replace
55 // the line below with these two lines if you prefer the stock client:
56 // require.resolve('webpack-dev-server/client') + '?/',
57 // require.resolve('webpack/hot/dev-server'),
58 // require.resolve('react-dev-utils/webpackHotDevClient'),
59 // We ship a few polyfills by default:
60 require.resolve('./polyfills'),
61 ]
62 // PROMETHEUS: rex autoloaded dependencies
63 .concat(prometheus.entry)
64 .concat([
65 // Finally, this is your app's code:
66 paths.appIndexJs
67 // We include the app code last so that if there is a runtime error during
68 // initialization, it doesn't blow up the WebpackDevServer client, and
69 // changing JS code would still trigger a refresh.
70 ]),
71 output: {
72 // Next line is not used in dev but WebpackDevServer crashes without it:
73 path: paths.appBuild,
74 // Add /* filename */ comments to generated require()s in the output.
75 pathinfo: true,
76 // This does not produce a real file. It's just the virtual path that is
77 // served by WebpackDevServer in development. This is the JS bundle
78 // containing code from all our entry points, and the Webpack runtime.
79 filename: 'js/bundle.js',
80 // This is the URL that app is served from. We use "/" in development.
81 publicPath: publicPath
82 },
83 resolve: {
84 // This allows you to set a fallback for where Webpack should look for modules.
85 // We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
86 // We use `fallback` instead of `root` because we want `node_modules` to "win"
87 // if there any conflicts. This matches Node resolution mechanism.
88 // https://github.com/facebookincubator/create-react-app/issues/253
89 fallback: [paths.appNodeModules].concat(paths.nodePaths),
90 // These are the reasonable defaults supported by the Node ecosystem.
91 // We also include JSX as a common component filename extension to support
92 // some tools, although we do not recommend using it, see:
93 // https://github.com/facebookincubator/create-react-app/issues/290
94 extensions: ['.js', '.json', '.jsx', ''],
95 alias: {
96 // Support React Native Web
97 // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
98 'react-native': 'react-native-web'
99 }
100 },
101 // @remove-on-eject-begin
102 // Resolve loaders (webpack plugins for CSS, images, transpilation) from the
103 // directory of `react-scripts` itself rather than the project directory.
104 resolveLoader: {
105 root: paths.ownNodeModules.concat(paths.nodePaths)
106 // PROMETHEUS: This is required for backward compat.
107 // moduleTemplates: ['*-loader']
108 },
109 // @remove-on-eject-end
110 module: {
111 // First, run the linter.
112 // It's important to do this before Babel processes the JS.
113 preLoaders: [
114 {
115 test: /\.(js|jsx)$/,
116 loader: 'eslint',
117 include: paths.appSrc,
118 }
119 ],
120 loaders: [
121 // ** ADDING/UPDATING LOADERS **
122 // The "url" loader handles all assets unless explicitly excluded.
123 // The `exclude` list *must* be updated with every change to loader extensions.
124 // When adding a new loader, you must add its `test`
125 // as a new entry in the `exclude` list for "url" loader.
126
127 // "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
128 // Otherwise, it acts like the "file" loader.
129 {
130 exclude: [
131 /\.html$/,
132 // We have to write /\.(js|jsx)(\?.*)?$/ rather than just /\.(js|jsx)$/
133 // because you might change the hot reloading server from the custom one
134 // to Webpack's built-in webpack-dev-server/client?/, which would not
135 // get properly excluded by /\.(js|jsx)$/ because of the query string.
136 // Webpack 2 fixes this, but for now we include this hack.
137 // https://github.com/facebookincubator/create-react-app/issues/1713
138 /\.(js|jsx)(\?.*)?$/,
139 /\.css$/,
140 /\.json$/,
141 /\.svg$/
142 ],
143 loader: 'url',
144 query: {
145 limit: 10000,
146 name: 'static/media/[name].[hash:8].[ext]'
147 }
148 },
149 // Process JS with Babel.
150 {
151 test: /\.(js|jsx)$/,
152 include: paths.appSrc,
153 loader: 'babel',
154 query: {
155 // @remove-on-eject-begin
156 babelrc: false,
157 presets: [require.resolve('babel-preset-prometheusresearch')],
158 // @remove-on-eject-end
159 // This is a feature of `babel-loader` for webpack (not Babel itself).
160 // It enables caching results in ./node_modules/.cache/babel-loader/
161 // directory for faster rebuilds.
162 cacheDirectory: true
163 }
164 },
165 // "postcss" loader applies autoprefixer to our CSS.
166 // "css" loader resolves paths in CSS and adds assets as dependencies.
167 // "style" loader turns CSS into JS modules that inject <style> tags.
168 // In production, we use a plugin to extract that CSS to a file, but
169 // in development "style" loader enables hot editing of CSS.
170 {
171 test: /\.css$/,
172 loader: 'style!css?importLoaders=1!postcss'
173 },
174 // JSON is not enabled by default in Webpack but both Node and Browserify
175 // allow it implicitly so we also enable it.
176 {
177 test: /\.json$/,
178 loader: 'json'
179 },
180 // "file" loader for svg
181 {
182 test: /\.svg$/,
183 loader: 'file',
184 query: {
185 name: 'static/media/[name].[hash:8].[ext]'
186 }
187 }
188 // ** STOP ** Are you adding a new loader?
189 // Remember to add the new extension(s) to the "url" loader exclusion list.
190 ]
191 },
192 // @remove-on-eject-begin
193 // Point ESLint to our predefined config.
194 eslint: {
195 configFile: path.join(__dirname, '../eslintrc'),
196 useEslintrc: false,
197 },
198 // @remove-on-eject-end
199 // We use PostCSS for autoprefixing only.
200 postcss: function() {
201 return [
202 autoprefixer({
203 browsers: [
204 '>1%',
205 'last 4 versions',
206 'Firefox ESR',
207 'not ie < 9', // React doesn't support IE8 anyway
208 ]
209 }),
210 ];
211 },
212 plugins: [
213 // Makes some environment variables available in index.html.
214 // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
215 // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
216 // In development, this will be an empty string.
217 // PROMETHEUS: disable
218 // new InterpolateHtmlPlugin(env.raw),
219 // Generates an `index.html` file with the <script> injected.
220 // PROMETHEUS: disable
221 // new HtmlWebpackPlugin({
222 // inject: true,
223 // template: paths.appHtml,
224 // }),
225 // Makes some environment variables available to the JS code, for example:
226 // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
227 new webpack.DefinePlugin(env.stringified),
228 // This is necessary to emit hot updates (currently CSS only):
229 // PROMETHEUS: disable
230 // new webpack.HotModuleReplacementPlugin(),
231 // Watcher doesn't work well if you mistype casing in a path so we use
232 // a plugin that prints an error when you attempt to do this.
233 // See https://github.com/facebookincubator/create-react-app/issues/240
234 new CaseSensitivePathsPlugin(),
235 // If you require a missing module and then `npm install` it, you still have
236 // to restart the development server for Webpack to discover it. This plugin
237 // makes the discovery automatic so you don't have to restart.
238 // See https://github.com/facebookincubator/create-react-app/issues/186
239 new WatchMissingNodeModulesPlugin(paths.appNodeModules),
240 // Generate a manifest file which contains a mapping of all asset filenames
241 // to their corresponding output file so that tools can pick it up without
242 // having to parse `index.html`.
243 new ManifestPlugin({
244 fileName: 'asset-manifest.json'
245 }),
246 ].concat(
247 prometheus.plugins
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 fs: 'empty',
253 net: 'empty',
254 tls: 'empty'
255 }
256};