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 |
|
12 | var autoprefixer = require('autoprefixer');
|
13 | var webpack = require('webpack');
|
14 | var HtmlWebpackPlugin = require('html-webpack-plugin');
|
15 | var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
16 | var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
17 | var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
18 | var getClientEnvironment = require('./env');
|
19 | var paths = require('./paths');
|
20 | var webpackConfigHelper = require('./webpackConfigHelper');
|
21 |
|
22 | // @remove-on-eject-begin
|
23 | // `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
|
24 | var 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.
|
29 | var 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.
|
33 | var publicUrl = '';
|
34 | // Get environment variables to inject into our app.
|
35 | var env = getClientEnvironment(publicUrl);
|
36 |
|
37 | var entryPoints = webpackConfigHelper.buildEntryPointConfig({
|
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 | base: [
|
49 | require.resolve('react-dev-utils/webpackHotDevClient'),
|
50 | // We ship a few polyfills by default:
|
51 | require.resolve('./polyfills')
|
52 | ],
|
53 | // Finally, this is your app's code:
|
54 | app: paths.appIndexJs
|
55 | });
|
56 |
|
57 | // This is the development configuration.
|
58 | // It is focused on developer experience and fast rebuilds.
|
59 | // The production configuration is different and lives in a separate file.
|
60 | module.exports = {
|
61 | // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
62 | // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
63 | devtool: 'cheap-module-source-map',
|
64 | // These are the "entry points" to our application.
|
65 | // This means they will be the "root" imports that are included in JS bundle.
|
66 | // The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
67 | entry: entryPoints,
|
68 | output: {
|
69 | // Next line is not used in dev but WebpackDevServer crashes without it:
|
70 | path: paths.appBuild,
|
71 | // Add /* filename */ comments to generated require()s in the output.
|
72 | pathinfo: true,
|
73 | // This does not produce a real file. It's just the virtual path that is
|
74 | // served by WebpackDevServer in development. This is the JS bundle
|
75 | // containing code from all our entry points, and the Webpack runtime.
|
76 | filename: 'static/js/[name].bundle.js',
|
77 | chunkFilename: 'static/js/[name].[id].chunk.js',
|
78 | // This is the URL that app is served from. We use "/" in development.
|
79 | publicPath: publicPath
|
80 | },
|
81 | resolve: {
|
82 | // This allows you to set a fallback for where Webpack should look for modules.
|
83 | // We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
|
84 | // We use `fallback` instead of `root` because we want `node_modules` to "win"
|
85 | // if there any conflicts. This matches Node resolution mechanism.
|
86 | // https://github.com/facebookincubator/create-react-app/issues/253
|
87 | fallback: paths.nodePaths,
|
88 | // These are the reasonable defaults supported by the Node ecosystem.
|
89 | // We also include JSX as a common component filename extension to support
|
90 | // some tools, although we do not recommend using it, see:
|
91 | // https://github.com/facebookincubator/create-react-app/issues/290
|
92 | extensions: ['.ts', '.tsx', '.js', '.json', '.jsx', ''],
|
93 | alias: {
|
94 | // Support React Native Web
|
95 | // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
96 | 'react-native': 'react-native-web'
|
97 | }
|
98 | },
|
99 | // @remove-on-eject-begin
|
100 | // Resolve loaders (webpack plugins for CSS, images, transpilation) from the
|
101 | // directory of `react-scripts` itself rather than the project directory.
|
102 | resolveLoader: {
|
103 | root: paths.ownNodeModules,
|
104 | moduleTemplates: ['*-loader']
|
105 | },
|
106 | // @remove-on-eject-end
|
107 | module: {
|
108 | // First, run the linter.
|
109 | // It's important to do this before Babel processes the JS.
|
110 | preLoaders: [
|
111 | {
|
112 | test: /\.(ts|tsx)$/,
|
113 | loader: 'tslint',
|
114 | include: paths.appSrc
|
115 | },
|
116 | {
|
117 | test: /\.(js|jsx)$/,
|
118 | loader: 'eslint',
|
119 | include: paths.appSrc,
|
120 | }
|
121 | ],
|
122 | loaders: [
|
123 | // ** ADDING/UPDATING LOADERS **
|
124 | // The "url" loader handles all assets unless explicitly excluded.
|
125 | // The `exclude` list *must* be updated with every change to loader extensions.
|
126 | // When adding a new loader, you must add its `test`
|
127 | // as a new entry in the `exclude` list for "url" loader.
|
128 |
|
129 | // "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
|
130 | // Otherwise, it acts like the "file" loader.
|
131 | {
|
132 | exclude: [
|
133 | /\.html$/,
|
134 | /\.(ts|tsx)$/,
|
135 | /\.(js|jsx)$/,
|
136 | /\.css$/,
|
137 | /\.scss$/,
|
138 | /\.json$/,
|
139 | /\.svg$/
|
140 | ],
|
141 | loader: 'url',
|
142 | query: {
|
143 | limit: 10000,
|
144 | name: 'static/media/[name].[hash:8].[ext]'
|
145 | }
|
146 | },
|
147 | // Process TS with Typescript.
|
148 | {
|
149 | test: /\.(ts|tsx)$/,
|
150 | include: paths.appSrc,
|
151 | loader: 'ts'
|
152 | },
|
153 | // Process JS with Babel.
|
154 | {
|
155 | test: /\.(js|jsx)$/,
|
156 | include: paths.appSrc,
|
157 | loader: 'babel',
|
158 | query: {
|
159 | // @remove-on-eject-begin
|
160 | babelrc: false,
|
161 | presets: [require.resolve('babel-preset-react-app')],
|
162 | // @remove-on-eject-end
|
163 | // This is a feature of `babel-loader` for webpack (not Babel itself).
|
164 | // It enables caching results in ./node_modules/.cache/babel-loader/
|
165 | // directory for faster rebuilds.
|
166 | cacheDirectory: true
|
167 | }
|
168 | },
|
169 | // "postcss" loader applies autoprefixer to our CSS.
|
170 | // "css" loader resolves paths in CSS and adds assets as dependencies.
|
171 | // "style" loader turns CSS into JS modules that inject <style> tags.
|
172 | // In production, we use a plugin to extract that CSS to a file, but
|
173 | // in development "style" loader enables hot editing of CSS.
|
174 | {
|
175 | test: /\.css$/,
|
176 | loader: 'style!css?sourceMap&importLoaders=1!postcss'
|
177 | },
|
178 | {
|
179 | test: /\.scss$/,
|
180 | loader: 'style!css?sourceMap&importLoaders=3!postcss!resolve-url!sass?sourceMap'
|
181 | },
|
182 | // JSON is not enabled by default in Webpack but both Node and Browserify
|
183 | // allow it implicitly so we also enable it.
|
184 | {
|
185 | test: /\.json$/,
|
186 | loader: 'json'
|
187 | },
|
188 | // "file" loader for svg
|
189 | {
|
190 | test: /\.svg$/,
|
191 | loader: 'file',
|
192 | query: {
|
193 | name: 'static/media/[name].[hash:8].[ext]'
|
194 | }
|
195 | }
|
196 | // ** STOP ** Are you adding a new loader?
|
197 | // Remember to add the new extension(s) to the "url" loader exclusion list.
|
198 | ]
|
199 | },
|
200 | // @remove-on-eject-begin
|
201 | // Point ESLint to our predefined config.
|
202 | eslint: {
|
203 | configFile: path.join(__dirname, '../.eslintrc'),
|
204 | useEslintrc: false
|
205 | },
|
206 | // @remove-on-eject-end
|
207 | // We use PostCSS for autoprefixing only.
|
208 | postcss: function() {
|
209 | return [
|
210 | autoprefixer({
|
211 | browsers: [
|
212 | '>1%',
|
213 | 'last 4 versions',
|
214 | 'Firefox ESR',
|
215 | 'not ie < 9', // React doesn't support IE8 anyway
|
216 | ]
|
217 | }),
|
218 | ];
|
219 | },
|
220 | plugins: [
|
221 | // Makes some environment variables available in index.html.
|
222 | // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
223 | // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
224 | // In development, this will be an empty string.
|
225 | new InterpolateHtmlPlugin(env.raw),
|
226 | // Makes some environment variables available to the JS code, for example:
|
227 | // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
228 | new webpack.DefinePlugin(env.stringified),
|
229 | // This is necessary to emit hot updates (currently CSS only):
|
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 | ].concat(webpackConfigHelper.buildHtmlWebpackPlugins({
|
241 | entryPointConfig: entryPoints
|
242 | })),
|
243 | // Some libraries import Node modules but don't use them in the browser.
|
244 | // Tell Webpack to provide empty mocks for them so importing them works.
|
245 | node: {
|
246 | fs: 'empty',
|
247 | net: 'empty',
|
248 | tls: 'empty'
|
249 | }
|
250 | };
|