mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Applied coding styles to config files
This commit is contained in:
parent
4e67798746
commit
fff18202fd
9 changed files with 635 additions and 544 deletions
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
@ -7,7 +6,8 @@ const paths = require('./paths');
|
||||||
// Make sure that including paths.js after env.js will read .env variables.
|
// Make sure that including paths.js after env.js will read .env variables.
|
||||||
delete require.cache[require.resolve('./paths')];
|
delete require.cache[require.resolve('./paths')];
|
||||||
|
|
||||||
const NODE_ENV = process.env.NODE_ENV;
|
const { NODE_ENV } = process.env;
|
||||||
|
|
||||||
if (!NODE_ENV) {
|
if (!NODE_ENV) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The NODE_ENV environment variable is required but was not specified.'
|
'The NODE_ENV environment variable is required but was not specified.'
|
||||||
|
@ -15,9 +15,10 @@ if (!NODE_ENV) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
||||||
var dotenvFiles = [
|
const dotenvFiles = [
|
||||||
`${paths.dotenv}.${NODE_ENV}.local`,
|
`${paths.dotenv}.${NODE_ENV}.local`,
|
||||||
`${paths.dotenv}.${NODE_ENV}`,
|
`${paths.dotenv}.${NODE_ENV}`,
|
||||||
|
|
||||||
// Don't include `.env.local` for `test` environment
|
// Don't include `.env.local` for `test` environment
|
||||||
// since normally you expect tests to produce the same
|
// since normally you expect tests to produce the same
|
||||||
// results for everyone
|
// results for everyone
|
||||||
|
@ -30,7 +31,7 @@ var dotenvFiles = [
|
||||||
// that have already been set. Variable expansion is supported in .env files.
|
// that have already been set. Variable expansion is supported in .env files.
|
||||||
// https://github.com/motdotla/dotenv
|
// https://github.com/motdotla/dotenv
|
||||||
// https://github.com/motdotla/dotenv-expand
|
// https://github.com/motdotla/dotenv-expand
|
||||||
dotenvFiles.forEach(dotenvFile => {
|
dotenvFiles.forEach((dotenvFile) => {
|
||||||
if (fs.existsSync(dotenvFile)) {
|
if (fs.existsSync(dotenvFile)) {
|
||||||
require('dotenv-expand')(
|
require('dotenv-expand')(
|
||||||
require('dotenv').config({
|
require('dotenv').config({
|
||||||
|
@ -50,10 +51,11 @@ dotenvFiles.forEach(dotenvFile => {
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||||
// We also resolve them to make sure all tools using them work consistently.
|
// We also resolve them to make sure all tools using them work consistently.
|
||||||
const appDirectory = fs.realpathSync(process.cwd());
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
|
|
||||||
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||||
.split(path.delimiter)
|
.split(path.delimiter)
|
||||||
.filter(folder => folder && !path.isAbsolute(folder))
|
.filter((folder) => folder && !path.isAbsolute(folder))
|
||||||
.map(folder => path.resolve(appDirectory, folder))
|
.map((folder) => path.resolve(appDirectory, folder))
|
||||||
.join(path.delimiter);
|
.join(path.delimiter);
|
||||||
|
|
||||||
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
||||||
|
@ -62,16 +64,19 @@ const REACT_APP = /^REACT_APP_/i;
|
||||||
|
|
||||||
function getClientEnvironment(publicUrl) {
|
function getClientEnvironment(publicUrl) {
|
||||||
const raw = Object.keys(process.env)
|
const raw = Object.keys(process.env)
|
||||||
.filter(key => REACT_APP.test(key))
|
.filter((key) => REACT_APP.test(key))
|
||||||
.reduce(
|
.reduce(
|
||||||
(env, key) => {
|
(env, key) => {
|
||||||
env[key] = process.env[key];
|
env[key] = process.env[key];
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
// Useful for determining whether we’re running in production mode.
|
// Useful for determining whether we’re running in production mode.
|
||||||
// Most importantly, it switches React into the correct mode.
|
// Most importantly, it switches React into the correct mode.
|
||||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||||
|
|
||||||
// Useful for resolving the correct path to static assets in `public`.
|
// Useful for resolving the correct path to static assets in `public`.
|
||||||
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
||||||
// This should only be used as an escape hatch. Normally you would put
|
// This should only be used as an escape hatch. Normally you would put
|
||||||
|
@ -79,10 +84,12 @@ function getClientEnvironment(publicUrl) {
|
||||||
PUBLIC_URL: publicUrl,
|
PUBLIC_URL: publicUrl,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stringify all values so we can feed into Webpack DefinePlugin
|
// Stringify all values so we can feed into Webpack DefinePlugin
|
||||||
const stringified = {
|
const stringified = {
|
||||||
'process.env': Object.keys(raw).reduce((env, key) => {
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
||||||
env[key] = JSON.stringify(raw[key]);
|
env[key] = JSON.stringify(raw[key]);
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}, {}),
|
}, {}),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// This is a custom Jest transformer turning style imports into empty objects.
|
// This is a custom Jest transformer turning style imports into empty objects.
|
||||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
@ -7,22 +6,23 @@ const url = require('url');
|
||||||
// Make sure any symlinks in the project folder are resolved:
|
// Make sure any symlinks in the project folder are resolved:
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/637
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||||
const appDirectory = fs.realpathSync(process.cwd());
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
|
||||||
|
|
||||||
const envPublicUrl = process.env.PUBLIC_URL;
|
const envPublicUrl = process.env.PUBLIC_URL;
|
||||||
|
|
||||||
function ensureSlash(path, needsSlash) {
|
function ensureSlash(path, needsSlash) {
|
||||||
const hasSlash = path.endsWith('/');
|
const hasSlash = path.endsWith('/');
|
||||||
|
|
||||||
if (hasSlash && !needsSlash) {
|
if (hasSlash && !needsSlash) {
|
||||||
return path.substr(path, path.length - 1);
|
return path.substr(path, path.length - 1);
|
||||||
} else if (!hasSlash && needsSlash) {
|
} else if (!hasSlash && needsSlash) {
|
||||||
return `${path}/`;
|
return `${path}/`;
|
||||||
} else {
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPublicUrl = appPackageJson =>
|
const getPublicUrl = (appPackageJson) =>
|
||||||
envPublicUrl || require(appPackageJson).homepage;
|
envPublicUrl || require(appPackageJson).homepage;
|
||||||
|
|
||||||
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
||||||
|
@ -34,6 +34,7 @@ const getPublicUrl = appPackageJson =>
|
||||||
function getServedPath(appPackageJson) {
|
function getServedPath(appPackageJson) {
|
||||||
const publicUrl = getPublicUrl(appPackageJson);
|
const publicUrl = getPublicUrl(appPackageJson);
|
||||||
const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||||
|
|
||||||
return ensureSlash(servedUrl, true);
|
return ensureSlash(servedUrl, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
if (typeof Promise === 'undefined') {
|
if (typeof Promise === 'undefined') {
|
||||||
// Rejection tracking prevents a common issue where React gets into an
|
// Rejection tracking prevents a common issue where React gets into an
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const autoprefixer = require('autoprefixer');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||||
|
@ -9,265 +8,301 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
const getClientEnvironment = require('./env');
|
const getClientEnvironment = require('./env');
|
||||||
const paths = require('./paths');
|
const paths = require('./paths');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
||||||
|
|
||||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
// In development, we always serve from the root. This makes config easier.
|
// In development, we always serve from the root. This makes config easier.
|
||||||
const publicPath = '/';
|
const publicPath = '/';
|
||||||
|
|
||||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
||||||
const publicUrl = '';
|
const publicUrl = '';
|
||||||
|
|
||||||
// Get environment variables to inject into our app.
|
// Get environment variables to inject into our app.
|
||||||
const env = getClientEnvironment(publicUrl);
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
const postCssLoader = {
|
const postCssLoader = {
|
||||||
loader: require.resolve('postcss-loader'),
|
loader: require.resolve('postcss-loader'),
|
||||||
options: {
|
options: {
|
||||||
// Necessary for external CSS imports to work
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
// Necessary for external CSS imports to work
|
||||||
ident: 'postcss',
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
plugins: () => [
|
ident: 'postcss',
|
||||||
require('postcss-flexbugs-fixes'),
|
plugins: () => [
|
||||||
autoprefixer({
|
require('postcss-flexbugs-fixes'),
|
||||||
browsers: [
|
autoprefixer({
|
||||||
'>1%',
|
browsers: [
|
||||||
'last 4 versions',
|
'>1%',
|
||||||
'Firefox ESR',
|
'last 4 versions',
|
||||||
'not ie < 9', // React doesn't support IE8 anyway
|
'Firefox ESR',
|
||||||
],
|
'not ie < 9',
|
||||||
flexbox: 'no-2009',
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
},
|
flexbox: 'no-2009',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the development configuration.
|
// This is the development configuration.
|
||||||
// It is focused on developer experience and fast rebuilds.
|
// It is focused on developer experience and fast rebuilds.
|
||||||
// The production configuration is different and lives in a separate file.
|
// The production configuration is different and lives in a separate file.
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
|
||||||
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
|
||||||
devtool: 'cheap-module-source-map',
|
|
||||||
// These are the "entry points" to our application.
|
|
||||||
// This means they will be the "root" imports that are included in JS bundle.
|
|
||||||
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
|
||||||
entry: [
|
|
||||||
// We ship a few polyfills by default:
|
|
||||||
require.resolve('./polyfills'),
|
|
||||||
// Include an alternative client for WebpackDevServer. A client's job is to
|
|
||||||
// connect to WebpackDevServer by a socket and get notified about changes.
|
|
||||||
// When you save a file, the client will either apply hot updates (in case
|
|
||||||
// of CSS changes), or refresh the page (in case of JS changes). When you
|
|
||||||
// make a syntax error, this client will display a syntax error overlay.
|
|
||||||
// Note: instead of the default WebpackDevServer client, we use a custom one
|
|
||||||
// to bring better experience for Create React App users. You can replace
|
|
||||||
// the line below with these two lines if you prefer the stock client:
|
|
||||||
// require.resolve('webpack-dev-server/client') + '?/',
|
|
||||||
// require.resolve('webpack/hot/dev-server'),
|
|
||||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
|
||||||
// Finally, this is your app's code:
|
|
||||||
paths.appIndexJs,
|
|
||||||
// We include the app code last so that if there is a runtime error during
|
|
||||||
// initialization, it doesn't blow up the WebpackDevServer client, and
|
|
||||||
// changing JS code would still trigger a refresh.
|
|
||||||
],
|
|
||||||
output: {
|
|
||||||
// Add /* filename */ comments to generated require()s in the output.
|
|
||||||
pathinfo: true,
|
|
||||||
// This does not produce a real file. It's just the virtual path that is
|
|
||||||
// served by WebpackDevServer in development. This is the JS bundle
|
|
||||||
// containing code from all our entry points, and the Webpack runtime.
|
|
||||||
filename: 'static/js/bundle.js',
|
|
||||||
// There are also additional JS chunk files if you use code splitting.
|
|
||||||
chunkFilename: 'static/js/[name].chunk.js',
|
|
||||||
// This is the URL that app is served from. We use "/" in development.
|
|
||||||
publicPath: publicPath,
|
|
||||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
||||||
devtoolModuleFilenameTemplate: info =>
|
|
||||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
// This allows you to set a fallback for where Webpack should look for modules.
|
|
||||||
// We placed these paths second because we want `node_modules` to "win"
|
|
||||||
// if there are any conflicts. This matches Node resolution mechanism.
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
|
||||||
modules: ['node_modules', paths.appNodeModules].concat(
|
|
||||||
// It is guaranteed to exist because we tweak it in `env.js`
|
|
||||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
|
||||||
),
|
|
||||||
// These are the reasonable defaults supported by the Node ecosystem.
|
|
||||||
// We also include JSX as a common component filename extension to support
|
|
||||||
// some tools, although we do not recommend using it, see:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
|
||||||
// `web` extension prefixes have been added for better support
|
|
||||||
// for React Native Web.
|
|
||||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
|
||||||
alias: {
|
|
||||||
|
|
||||||
// Support React Native Web
|
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
||||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
||||||
'react-native': 'react-native-web',
|
devtool: 'cheap-module-source-map',
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
|
||||||
// This often causes confusion because we only process files within src/ with babel.
|
|
||||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
||||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
||||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
||||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
strictExportPresence: true,
|
|
||||||
rules: [
|
|
||||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
|
||||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
|
||||||
// { parser: { requireEnsure: false } },
|
|
||||||
|
|
||||||
// First, run the linter.
|
// These are the "entry points" to our application.
|
||||||
// It's important to do this before Babel processes the JS.
|
// This means they will be the "root" imports that are included in JS bundle.
|
||||||
{
|
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
||||||
test: /\.(js|jsx|mjs)$/,
|
entry: [
|
||||||
enforce: 'pre',
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
options: {
|
|
||||||
formatter: eslintFormatter,
|
|
||||||
eslintPath: require.resolve('eslint'),
|
|
||||||
|
|
||||||
},
|
// We ship a few polyfills by default:
|
||||||
loader: require.resolve('eslint-loader'),
|
require.resolve('./polyfills'),
|
||||||
},
|
|
||||||
],
|
|
||||||
include: paths.appSrc,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// "oneOf" will traverse all following loaders until one will
|
|
||||||
// match the requirements. When no loader matches it will fall
|
|
||||||
// back to the "file" loader at the end of the loader list.
|
|
||||||
oneOf: [
|
|
||||||
// "url" loader works like "file" loader except that it embeds assets
|
|
||||||
// smaller than specified limit in bytes as data URLs to avoid requests.
|
|
||||||
// A missing `test` is equivalent to a match.
|
|
||||||
{
|
|
||||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
||||||
loader: require.resolve('url-loader'),
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Process JS with Babel.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
include: paths.appSrc,
|
|
||||||
loader: require.resolve('babel-loader'),
|
|
||||||
options: {
|
|
||||||
|
|
||||||
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||||
// It enables caching results in ./node_modules/.cache/babel-loader/
|
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||||
// directory for faster rebuilds.
|
// When you save a file, the client will either apply hot updates (in case
|
||||||
cacheDirectory: true,
|
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||||
},
|
// make a syntax error, this client will display a syntax error overlay.
|
||||||
},
|
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||||
// "postcss" loader applies autoprefixer to our CSS.
|
// to bring better experience for Create React App users. You can replace
|
||||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
// the line below with these two lines if you prefer the stock client:
|
||||||
// "style" loader turns CSS into JS modules that inject <style> tags.
|
// require.resolve('webpack-dev-server/client') + '?/',
|
||||||
// In production, we use a plugin to extract that CSS to a file, but
|
// require.resolve('webpack/hot/dev-server'),
|
||||||
// in development "style" loader enables hot editing of CSS.
|
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||||
{
|
|
||||||
test: /\.css$/,
|
// Finally, this is your app's code:
|
||||||
use: [
|
paths.appIndexJs,
|
||||||
require.resolve('style-loader'),
|
|
||||||
{
|
// We include the app code last so that if there is a runtime error during
|
||||||
loader: require.resolve('css-loader'),
|
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||||
options: {
|
// changing JS code would still trigger a refresh.
|
||||||
importLoaders: 1,
|
],
|
||||||
},
|
output: {
|
||||||
},
|
|
||||||
postCssLoader,
|
// Add /* filename */ comments to generated require()s in the output.
|
||||||
],
|
pathinfo: true,
|
||||||
},
|
|
||||||
{
|
// This does not produce a real file. It's just the virtual path that is
|
||||||
test: /\.scss$/,
|
// served by WebpackDevServer in development. This is the JS bundle
|
||||||
use: ExtractTextPlugin.extract({
|
// containing code from all our entry points, and the Webpack runtime.
|
||||||
fallback: 'style-loader',
|
filename: 'static/js/bundle.js',
|
||||||
use: ['css-loader', 'sass-loader', postCssLoader]
|
|
||||||
})
|
// There are also additional JS chunk files if you use code splitting.
|
||||||
},
|
chunkFilename: 'static/js/[name].chunk.js',
|
||||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
||||||
// When you `import` an asset, you get its (virtual) filename.
|
// This is the URL that app is served from. We use "/" in development.
|
||||||
// In production, they would get copied to the `build` folder.
|
publicPath,
|
||||||
// This loader doesn't use a "test" so it will catch all modules
|
|
||||||
// that fall through the other loaders.
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
{
|
devtoolModuleFilenameTemplate: (info) =>
|
||||||
// Exclude `js` files to keep "css" loader working as it injects
|
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||||
// its runtime that would otherwise processed through "file" loader.
|
},
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
resolve: {
|
||||||
// by webpacks internal loaders.
|
|
||||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
loader: require.resolve('file-loader'),
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
options: {
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
},
|
modules: [ 'node_modules', paths.appNodeModules ].concat(
|
||||||
},
|
|
||||||
],
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
},
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
// ** STOP ** Are you adding a new loader?
|
),
|
||||||
// Make sure to add the new loader(s) before the "file" loader.
|
|
||||||
],
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
|
// We also include JSX as a common component filename extension to support
|
||||||
|
// some tools, although we do not recommend using it, see:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: [ '.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx' ],
|
||||||
|
alias: {
|
||||||
|
|
||||||
|
// Support React Native Web
|
||||||
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
|
'react-native': 'react-native-web',
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// Makes some environment variables available in index.html.
|
|
||||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
// In development, this will be an empty string.
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
new InterpolateHtmlPlugin(env.raw),
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
// Generates an `index.html` file with the <script> injected.
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
new HtmlWebpackPlugin({
|
new ModuleScopePlugin(paths.appSrc, [ paths.appPackageJson ]),
|
||||||
inject: true,
|
|
||||||
template: paths.appHtml,
|
|
||||||
}),
|
|
||||||
// Add module names to factory functions so they appear in browser profiler.
|
|
||||||
new webpack.NamedModulesPlugin(),
|
|
||||||
// Makes some environment variables available to the JS code, for example:
|
|
||||||
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
|
||||||
new webpack.DefinePlugin(env.stringified),
|
|
||||||
// This is necessary to emit hot updates (currently CSS only):
|
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
|
||||||
// Watcher doesn't work well if you mistype casing in a path so we use
|
|
||||||
// a plugin that prints an error when you attempt to do this.
|
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/240
|
|
||||||
new CaseSensitivePathsPlugin(),
|
|
||||||
// If you require a missing module and then `npm install` it, you still have
|
|
||||||
// to restart the development server for Webpack to discover it. This plugin
|
|
||||||
// makes the discovery automatic so you don't have to restart.
|
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/186
|
|
||||||
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
|
||||||
// Moment.js is an extremely popular library that bundles large locale files
|
|
||||||
// by default due to how Webpack interprets its code. This is a practical
|
|
||||||
// solution that requires the user to opt into importing specific locales.
|
|
||||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
||||||
// You can remove this if you don't use Moment.js:
|
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
||||||
new ExtractTextPlugin('main.css'),
|
|
||||||
],
|
],
|
||||||
// Some libraries import Node modules but don't use them in the browser.
|
},
|
||||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
module: {
|
||||||
node: {
|
strictExportPresence: true,
|
||||||
dgram: 'empty',
|
rules: [
|
||||||
fs: 'empty',
|
|
||||||
net: 'empty',
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
tls: 'empty',
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
child_process: 'empty',
|
// { parser: { requireEnsure: false } },
|
||||||
},
|
|
||||||
// Turn off performance hints during development because we don't do any
|
// First, run the linter.
|
||||||
// splitting or minification in interest of speed. These warnings become
|
// It's important to do this before Babel processes the JS.
|
||||||
// cumbersome.
|
{
|
||||||
performance: {
|
test: /\.(js|jsx|mjs)$/,
|
||||||
hints: false,
|
enforce: 'pre',
|
||||||
},
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
|
||||||
|
// "url" loader works like "file" loader except that it embeds assets
|
||||||
|
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||||
|
// A missing `test` is equivalent to a match.
|
||||||
|
{
|
||||||
|
test: [ /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/ ],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appSrc,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
|
||||||
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||||
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||||
|
// directory for faster rebuilds.
|
||||||
|
cacheDirectory: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||||
|
// In production, we use a plugin to extract that CSS to a file, but
|
||||||
|
// in development "style" loader enables hot editing of CSS.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: [
|
||||||
|
require.resolve('style-loader'),
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
postCssLoader,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.scss$/,
|
||||||
|
use: ExtractTextPlugin.extract({
|
||||||
|
fallback: 'style-loader',
|
||||||
|
use: [ 'css-loader', 'sass-loader', postCssLoader ],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
|
||||||
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||||
|
// When you `import` an asset, you get its (virtual) filename.
|
||||||
|
// In production, they would get copied to the `build` folder.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// its runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [ /\.(js|jsx|mjs)$/, /\.html$/, /\.json$/ ],
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In development, this will be an empty string.
|
||||||
|
new InterpolateHtmlPlugin(env.raw),
|
||||||
|
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Add module names to factory functions so they appear in browser profiler.
|
||||||
|
new webpack.NamedModulesPlugin(),
|
||||||
|
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
|
||||||
|
// This is necessary to emit hot updates (currently CSS only):
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
|
|
||||||
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||||
|
// a plugin that prints an error when you attempt to do this.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/240
|
||||||
|
new CaseSensitivePathsPlugin(),
|
||||||
|
|
||||||
|
// If you require a missing module and then `npm install` it, you still have
|
||||||
|
// to restart the development server for Webpack to discover it. This plugin
|
||||||
|
// makes the discovery automatic so you don't have to restart.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/186
|
||||||
|
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||||
|
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
new ExtractTextPlugin('main.css'),
|
||||||
|
],
|
||||||
|
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
|
||||||
|
// Turn off performance hints during development because we don't do any
|
||||||
|
// splitting or minification in interest of speed. These warnings become
|
||||||
|
// cumbersome.
|
||||||
|
performance: {
|
||||||
|
hints: false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const autoprefixer = require('autoprefixer');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
@ -16,22 +15,26 @@ const getClientEnvironment = require('./env');
|
||||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
// It requires a trailing slash, or the file assets will get an incorrect path.
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
const publicPath = paths.servedPath;
|
const publicPath = paths.servedPath;
|
||||||
|
|
||||||
// Some apps do not use client-side routing with pushState.
|
// Some apps do not use client-side routing with pushState.
|
||||||
// For these, "homepage" can be set to "." to enable relative asset paths.
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
const shouldUseRelativeAssetPaths = publicPath === './';
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
|
|
||||||
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
|
|
||||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
const publicUrl = publicPath.slice(0, -1);
|
const publicUrl = publicPath.slice(0, -1);
|
||||||
|
|
||||||
// Get environment variables to inject into our app.
|
// Get environment variables to inject into our app.
|
||||||
const env = getClientEnvironment(publicUrl);
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
// Assert this just to be safe.
|
// Assert this just to be safe.
|
||||||
// Development builds of React are slow and not intended for production.
|
// Development builds of React are slow and not intended for production.
|
||||||
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||||
throw new Error('Production builds must have NODE_ENV=production.');
|
throw new Error('Production builds must have NODE_ENV=production.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: defined here because it will be used more than once.
|
// Note: defined here because it will be used more than once.
|
||||||
|
@ -41,305 +44,342 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
|
||||||
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||||
// However, our output is structured with css, js and media folders.
|
// However, our output is structured with css, js and media folders.
|
||||||
// To have this structure working with relative paths, we have to use custom options.
|
// To have this structure working with relative paths, we have to use custom options.
|
||||||
|
// Making sure that the publicPath goes back to to build folder.
|
||||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||||
? // Making sure that the publicPath goes back to to build folder.
|
? { publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||||
{publicPath: Array(cssFilename.split('/').length).join('../')}
|
: {};
|
||||||
: {};
|
|
||||||
|
|
||||||
// This is the production configuration.
|
// This is the production configuration.
|
||||||
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||||
// The development configuration is different and lives in a separate file.
|
// The development configuration is different and lives in a separate file.
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Don't attempt to continue if there are any errors.
|
|
||||||
bail: true,
|
|
||||||
// We generate sourcemaps in production. This is slow but gives good results.
|
|
||||||
// You can exclude the *.map files from the build during deployment.
|
|
||||||
devtool: shouldUseSourceMap ? 'source-map' : false,
|
|
||||||
// In production, we only want to load the polyfills and the app code.
|
|
||||||
entry: [require.resolve('./polyfills'), paths.appIndexJs],
|
|
||||||
output: {
|
|
||||||
// The build folder.
|
|
||||||
path: paths.appBuild,
|
|
||||||
// Generated JS file names (with nested folders).
|
|
||||||
// There will be one main bundle, and one file per asynchronous chunk.
|
|
||||||
// We don't currently advertise code splitting but Webpack supports it.
|
|
||||||
filename: 'static/js/[name].[chunkhash:8].js',
|
|
||||||
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
|
|
||||||
// We inferred the "public path" (such as / or /my-project) from homepage.
|
|
||||||
publicPath: publicPath,
|
|
||||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
||||||
devtoolModuleFilenameTemplate: info =>
|
|
||||||
path
|
|
||||||
.relative(paths.appSrc, info.absoluteResourcePath)
|
|
||||||
.replace(/\\/g, '/'),
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
// This allows you to set a fallback for where Webpack should look for modules.
|
|
||||||
// We placed these paths second because we want `node_modules` to "win"
|
|
||||||
// if there are any conflicts. This matches Node resolution mechanism.
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
|
||||||
modules: ['node_modules', paths.appNodeModules].concat(
|
|
||||||
// It is guaranteed to exist because we tweak it in `env.js`
|
|
||||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
|
||||||
),
|
|
||||||
// These are the reasonable defaults supported by the Node ecosystem.
|
|
||||||
// We also include JSX as a common component filename extension to support
|
|
||||||
// some tools, although we do not recommend using it, see:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
|
||||||
// `web` extension prefixes have been added for better support
|
|
||||||
// for React Native Web.
|
|
||||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
|
||||||
alias: {
|
|
||||||
|
|
||||||
// Support React Native Web
|
// Don't attempt to continue if there are any errors.
|
||||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
bail: true,
|
||||||
'react-native': 'react-native-web',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
|
||||||
// This often causes confusion because we only process files within src/ with babel.
|
|
||||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
||||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
||||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
||||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
strictExportPresence: true,
|
|
||||||
rules: [
|
|
||||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
|
||||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
|
||||||
// { parser: { requireEnsure: false } },
|
|
||||||
|
|
||||||
// First, run the linter.
|
// We generate sourcemaps in production. This is slow but gives good results.
|
||||||
// It's important to do this before Babel processes the JS.
|
// You can exclude the *.map files from the build during deployment.
|
||||||
{
|
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
enforce: 'pre',
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
options: {
|
|
||||||
formatter: eslintFormatter,
|
|
||||||
eslintPath: require.resolve('eslint'),
|
|
||||||
|
|
||||||
},
|
// In production, we only want to load the polyfills and the app code.
|
||||||
loader: require.resolve('eslint-loader'),
|
entry: [ require.resolve('./polyfills'), paths.appIndexJs ],
|
||||||
},
|
output: {
|
||||||
],
|
|
||||||
include: paths.appSrc,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// "oneOf" will traverse all following loaders until one will
|
|
||||||
// match the requirements. When no loader matches it will fall
|
|
||||||
// back to the "file" loader at the end of the loader list.
|
|
||||||
oneOf: [
|
|
||||||
// "url" loader works just like "file" loader but it also embeds
|
|
||||||
// assets smaller than specified size as data URLs to avoid requests.
|
|
||||||
{
|
|
||||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
||||||
loader: require.resolve('url-loader'),
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Process JS with Babel.
|
|
||||||
{
|
|
||||||
test: /\.(js|jsx|mjs)$/,
|
|
||||||
include: paths.appSrc,
|
|
||||||
loader: require.resolve('babel-loader'),
|
|
||||||
options: {
|
|
||||||
|
|
||||||
compact: true,
|
// The build folder.
|
||||||
},
|
path: paths.appBuild,
|
||||||
},
|
|
||||||
// The notation here is somewhat confusing.
|
// Generated JS file names (with nested folders).
|
||||||
// "postcss" loader applies autoprefixer to our CSS.
|
// There will be one main bundle, and one file per asynchronous chunk.
|
||||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
// We don't currently advertise code splitting but Webpack supports it.
|
||||||
// "style" loader normally turns CSS into JS modules injecting <style>,
|
filename: 'static/js/[name].[chunkhash:8].js',
|
||||||
// but unlike in development configuration, we do something different.
|
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
|
||||||
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
|
||||||
// (second argument), then grabs the result CSS and puts it into a
|
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||||
// separate file in our build process. This way we actually ship
|
publicPath,
|
||||||
// a single CSS file in production instead of JS code injecting <style>
|
|
||||||
// tags. If you use code splitting, however, any async bundles will still
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
// use the "style" loader inside the async code so CSS from them won't be
|
devtoolModuleFilenameTemplate: (info) =>
|
||||||
// in the main CSS file.
|
path
|
||||||
{
|
.relative(paths.appSrc, info.absoluteResourcePath)
|
||||||
test: [/\.css$/, /\.scss$/],
|
.replace(/\\/g, '/'),
|
||||||
loader: ExtractTextPlugin.extract(
|
},
|
||||||
Object.assign(
|
resolve: {
|
||||||
{
|
|
||||||
fallback: {
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
loader: require.resolve('style-loader'),
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
options: {
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
hmr: false,
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
},
|
modules: [ 'node_modules', paths.appNodeModules ].concat(
|
||||||
},
|
|
||||||
use: [
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
{
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
loader: require.resolve('css-loader'),
|
),
|
||||||
options: {
|
|
||||||
importLoaders: 1,
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
minimize: true,
|
// We also include JSX as a common component filename extension to support
|
||||||
sourceMap: shouldUseSourceMap,
|
// some tools, although we do not recommend using it, see:
|
||||||
},
|
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||||
},
|
// `web` extension prefixes have been added for better support
|
||||||
{
|
// for React Native Web.
|
||||||
loader: require.resolve('sass-loader'),
|
extensions: [ '.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx' ],
|
||||||
},
|
alias: {
|
||||||
{
|
|
||||||
loader: require.resolve('postcss-loader'),
|
// Support React Native Web
|
||||||
options: {
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
// Necessary for external CSS imports to work
|
'react-native': 'react-native-web',
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
|
||||||
ident: 'postcss',
|
|
||||||
plugins: () => [
|
|
||||||
require('postcss-flexbugs-fixes'),
|
|
||||||
autoprefixer({
|
|
||||||
browsers: [
|
|
||||||
'>1%',
|
|
||||||
'last 4 versions',
|
|
||||||
'Firefox ESR',
|
|
||||||
'not ie < 9', // React doesn't support IE8 anyway
|
|
||||||
],
|
|
||||||
flexbox: 'no-2009',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
extractTextPluginOptions
|
|
||||||
)
|
|
||||||
),
|
|
||||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
|
||||||
},
|
|
||||||
// "file" loader makes sure assets end up in the `build` folder.
|
|
||||||
// When you `import` an asset, you get its filename.
|
|
||||||
// This loader doesn't use a "test" so it will catch all modules
|
|
||||||
// that fall through the other loaders.
|
|
||||||
{
|
|
||||||
loader: require.resolve('file-loader'),
|
|
||||||
// Exclude `js` files to keep "css" loader working as it injects
|
|
||||||
// it's runtime that would otherwise processed through "file" loader.
|
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
|
||||||
// by webpacks internal loaders.
|
|
||||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
|
||||||
options: {
|
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// ** STOP ** Are you adding a new loader?
|
|
||||||
// Make sure to add the new loader(s) before the "file" loader.
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// Makes some environment variables available in index.html.
|
|
||||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
// In production, it will be an empty string unless you specify "homepage"
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
// in `package.json`, in which case it will be the pathname of that URL.
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
new InterpolateHtmlPlugin(env.raw),
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
// Generates an `index.html` file with the <script> injected.
|
new ModuleScopePlugin(paths.appSrc, [ paths.appPackageJson ]),
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
inject: true,
|
|
||||||
template: paths.appHtml,
|
|
||||||
minify: {
|
|
||||||
removeComments: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
removeRedundantAttributes: true,
|
|
||||||
useShortDoctype: true,
|
|
||||||
removeEmptyAttributes: true,
|
|
||||||
removeStyleLinkTypeAttributes: true,
|
|
||||||
keepClosingSlash: true,
|
|
||||||
minifyJS: true,
|
|
||||||
minifyCSS: true,
|
|
||||||
minifyURLs: true,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
// Makes some environment variables available to the JS code, for example:
|
|
||||||
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
|
||||||
// It is absolutely essential that NODE_ENV was set to production here.
|
|
||||||
// Otherwise React will be compiled in the very slow development mode.
|
|
||||||
new webpack.DefinePlugin(env.stringified),
|
|
||||||
// Minify the code.
|
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
|
||||||
compress: {
|
|
||||||
warnings: false,
|
|
||||||
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2376
|
|
||||||
// Pending further investigation:
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
||||||
comparisons: false,
|
|
||||||
},
|
|
||||||
mangle: {
|
|
||||||
safari10: true,
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
comments: false,
|
|
||||||
// Turned on because emoji and regex is not minified properly using default
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2488
|
|
||||||
ascii_only: true,
|
|
||||||
},
|
|
||||||
sourceMap: shouldUseSourceMap,
|
|
||||||
}),
|
|
||||||
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
|
||||||
new ExtractTextPlugin({
|
|
||||||
filename: cssFilename,
|
|
||||||
}),
|
|
||||||
// Generate a manifest file which contains a mapping of all asset filenames
|
|
||||||
// to their corresponding output file so that tools can pick it up without
|
|
||||||
// having to parse `index.html`.
|
|
||||||
new ManifestPlugin({
|
|
||||||
fileName: 'asset-manifest.json',
|
|
||||||
}),
|
|
||||||
// Generate a service worker script that will precache, and keep up to date,
|
|
||||||
// the HTML & assets that are part of the Webpack build.
|
|
||||||
new SWPrecacheWebpackPlugin({
|
|
||||||
// By default, a cache-busting query parameter is appended to requests
|
|
||||||
// used to populate the caches, to ensure the responses are fresh.
|
|
||||||
// If a URL is already hashed by Webpack, then there is no concern
|
|
||||||
// about it being stale, and the cache-busting can be skipped.
|
|
||||||
dontCacheBustUrlsMatching: /\.\w{8}\./,
|
|
||||||
filename: 'service-worker.js',
|
|
||||||
logger(message) {
|
|
||||||
if (message.indexOf('Total precache size is') === 0) {
|
|
||||||
// This message occurs for every build and is a bit too noisy.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (message.indexOf('Skipping static resource') === 0) {
|
|
||||||
// This message obscures real errors so we ignore it.
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2612
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(message);
|
|
||||||
},
|
|
||||||
minify: true,
|
|
||||||
// For unknown URLs, fallback to the index page
|
|
||||||
navigateFallback: publicUrl + '/index.html',
|
|
||||||
// Ignores URLs starting from /__ (useful for Firebase):
|
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
|
|
||||||
navigateFallbackWhitelist: [/^(?!\/__).*/],
|
|
||||||
// Don't precache sourcemaps (they're large) and build asset manifest:
|
|
||||||
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
|
|
||||||
}),
|
|
||||||
// Moment.js is an extremely popular library that bundles large locale files
|
|
||||||
// by default due to how Webpack interprets its code. This is a practical
|
|
||||||
// solution that requires the user to opt into importing specific locales.
|
|
||||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
||||||
// You can remove this if you don't use Moment.js:
|
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
||||||
],
|
],
|
||||||
// Some libraries import Node modules but don't use them in the browser.
|
},
|
||||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
module: {
|
||||||
node: {
|
strictExportPresence: true,
|
||||||
dgram: 'empty',
|
rules: [
|
||||||
fs: 'empty',
|
|
||||||
net: 'empty',
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
tls: 'empty',
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
child_process: 'empty',
|
// { parser: { requireEnsure: false } },
|
||||||
},
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
|
||||||
|
// "url" loader works just like "file" loader but it also embeds
|
||||||
|
// assets smaller than specified size as data URLs to avoid requests.
|
||||||
|
{
|
||||||
|
test: [ /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/ ],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appSrc,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
|
||||||
|
compact: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// The notation here is somewhat confusing.
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||||
|
// but unlike in development configuration, we do something different.
|
||||||
|
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||||
|
// (second argument), then grabs the result CSS and puts it into a
|
||||||
|
// separate file in our build process. This way we actually ship
|
||||||
|
// a single CSS file in production instead of JS code injecting <style>
|
||||||
|
// tags. If you use code splitting, however, any async bundles will still
|
||||||
|
// use the "style" loader inside the async code so CSS from them won't be
|
||||||
|
// in the main CSS file.
|
||||||
|
{
|
||||||
|
test: [ /\.css$/, /\.scss$/ ],
|
||||||
|
loader: ExtractTextPlugin.extract(
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
fallback: {
|
||||||
|
loader: require.resolve('style-loader'),
|
||||||
|
options: {
|
||||||
|
hmr: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
minimize: true,
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('sass-loader'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
autoprefixer({
|
||||||
|
browsers: [
|
||||||
|
'>1%',
|
||||||
|
'last 4 versions',
|
||||||
|
'Firefox ESR',
|
||||||
|
'not ie < 9',
|
||||||
|
],
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
extractTextPluginOptions
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||||
|
},
|
||||||
|
|
||||||
|
// "file" loader makes sure assets end up in the `build` folder.
|
||||||
|
// When you `import` an asset, you get its filename.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// it's runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [ /\.(js|jsx|mjs)$/, /\.html$/, /\.json$/ ],
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In production, it will be an empty string unless you specify "homepage"
|
||||||
|
// in `package.json`, in which case it will be the pathname of that URL.
|
||||||
|
new InterpolateHtmlPlugin(env.raw),
|
||||||
|
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
minify: {
|
||||||
|
removeComments: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
removeRedundantAttributes: true,
|
||||||
|
useShortDoctype: true,
|
||||||
|
removeEmptyAttributes: true,
|
||||||
|
removeStyleLinkTypeAttributes: true,
|
||||||
|
keepClosingSlash: true,
|
||||||
|
minifyJS: true,
|
||||||
|
minifyCSS: true,
|
||||||
|
minifyURLs: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
|
// It is absolutely essential that NODE_ENV was set to production here.
|
||||||
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
|
||||||
|
// Minify the code.
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compress: {
|
||||||
|
warnings: false,
|
||||||
|
|
||||||
|
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2376
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||||
|
comparisons: false,
|
||||||
|
},
|
||||||
|
mangle: {
|
||||||
|
safari10: true,
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
comments: false,
|
||||||
|
|
||||||
|
// Turned on because emoji and regex is not minified properly using default
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2488
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||||
|
new ExtractTextPlugin({
|
||||||
|
filename: cssFilename,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Generate a manifest file which contains a mapping of all asset filenames
|
||||||
|
// to their corresponding output file so that tools can pick it up without
|
||||||
|
// having to parse `index.html`.
|
||||||
|
new ManifestPlugin({
|
||||||
|
fileName: 'asset-manifest.json',
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Generate a service worker script that will precache, and keep up to date,
|
||||||
|
// the HTML & assets that are part of the Webpack build.
|
||||||
|
new SWPrecacheWebpackPlugin({
|
||||||
|
|
||||||
|
// By default, a cache-busting query parameter is appended to requests
|
||||||
|
// used to populate the caches, to ensure the responses are fresh.
|
||||||
|
// If a URL is already hashed by Webpack, then there is no concern
|
||||||
|
// about it being stale, and the cache-busting can be skipped.
|
||||||
|
dontCacheBustUrlsMatching: /\.\w{8}\./,
|
||||||
|
filename: 'service-worker.js',
|
||||||
|
logger(message) {
|
||||||
|
if (message.indexOf('Total precache size is') === 0) {
|
||||||
|
// This message occurs for every build and is a bit too noisy.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message.indexOf('Skipping static resource') === 0) {
|
||||||
|
// This message obscures real errors so we ignore it.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2612
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(message); // eslint-disable-line
|
||||||
|
},
|
||||||
|
minify: true,
|
||||||
|
|
||||||
|
// For unknown URLs, fallback to the index page
|
||||||
|
navigateFallback: `${publicUrl}/index.html`,
|
||||||
|
|
||||||
|
// Ignores URLs starting from /__ (useful for Firebase):
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
|
||||||
|
navigateFallbackWhitelist: [ /^(?!\/__).*/ ],
|
||||||
|
|
||||||
|
// Don't precache sourcemaps (they're large) and build asset manifest:
|
||||||
|
staticFileGlobsIgnorePatterns: [ /\.map$/, /asset-manifest\.json$/ ],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
],
|
||||||
|
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||||
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||||
|
@ -11,6 +10,7 @@ const host = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
module.exports = function(proxy, allowedHost) {
|
module.exports = function(proxy, allowedHost) {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
||||||
// websites from potentially accessing local content through DNS rebinding:
|
// websites from potentially accessing local content through DNS rebinding:
|
||||||
// https://github.com/webpack/webpack-dev-server/issues/887
|
// https://github.com/webpack/webpack-dev-server/issues/887
|
||||||
|
@ -29,11 +29,14 @@ module.exports = function(proxy, allowedHost) {
|
||||||
// really know what you're doing with a special environment variable.
|
// really know what you're doing with a special environment variable.
|
||||||
disableHostCheck:
|
disableHostCheck:
|
||||||
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
||||||
|
|
||||||
// Enable gzip compression of generated files.
|
// Enable gzip compression of generated files.
|
||||||
compress: true,
|
compress: true,
|
||||||
|
|
||||||
// Silence WebpackDevServer's own logs since they're generally not useful.
|
// Silence WebpackDevServer's own logs since they're generally not useful.
|
||||||
// It will still show compile warnings and errors with this setting.
|
// It will still show compile warnings and errors with this setting.
|
||||||
clientLogLevel: 'none',
|
clientLogLevel: 'none',
|
||||||
|
|
||||||
// By default WebpackDevServer serves physical files from current directory
|
// By default WebpackDevServer serves physical files from current directory
|
||||||
// in addition to all the virtual build products that it serves from memory.
|
// in addition to all the virtual build products that it serves from memory.
|
||||||
// This is confusing because those files won’t automatically be available in
|
// This is confusing because those files won’t automatically be available in
|
||||||
|
@ -49,20 +52,25 @@ module.exports = function(proxy, allowedHost) {
|
||||||
// for some reason broken when imported through Webpack. If you just want to
|
// for some reason broken when imported through Webpack. If you just want to
|
||||||
// use an image, put it in `src` and `import` it from JavaScript instead.
|
// use an image, put it in `src` and `import` it from JavaScript instead.
|
||||||
contentBase: paths.appPublic,
|
contentBase: paths.appPublic,
|
||||||
|
|
||||||
// By default files from `contentBase` will not trigger a page reload.
|
// By default files from `contentBase` will not trigger a page reload.
|
||||||
watchContentBase: true,
|
watchContentBase: true,
|
||||||
|
|
||||||
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
||||||
// for the WebpackDevServer client so it can learn when the files were
|
// for the WebpackDevServer client so it can learn when the files were
|
||||||
// updated. The WebpackDevServer client is included as an entry point
|
// updated. The WebpackDevServer client is included as an entry point
|
||||||
// in the Webpack development configuration. Note that only changes
|
// in the Webpack development configuration. Note that only changes
|
||||||
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
||||||
hot: true,
|
hot: true,
|
||||||
|
|
||||||
// It is important to tell WebpackDevServer to use the same "root" path
|
// It is important to tell WebpackDevServer to use the same "root" path
|
||||||
// as we specified in the config. In development, we always serve from /.
|
// as we specified in the config. In development, we always serve from /.
|
||||||
publicPath: config.output.publicPath,
|
publicPath: config.output.publicPath,
|
||||||
|
|
||||||
// WebpackDevServer is noisy by default so we emit custom message instead
|
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||||
// by listening to the compiler events with `compiler.plugin` calls above.
|
// by listening to the compiler events with `compiler.plugin` calls above.
|
||||||
quiet: true,
|
quiet: true,
|
||||||
|
|
||||||
// Reportedly, this avoids CPU overload on some systems.
|
// Reportedly, this avoids CPU overload on some systems.
|
||||||
// https://github.com/facebookincubator/create-react-app/issues/293
|
// https://github.com/facebookincubator/create-react-app/issues/293
|
||||||
// src/node_modules is not ignored to support absolute imports
|
// src/node_modules is not ignored to support absolute imports
|
||||||
|
@ -70,11 +78,13 @@ module.exports = function(proxy, allowedHost) {
|
||||||
watchOptions: {
|
watchOptions: {
|
||||||
ignored: ignoredFiles(paths.appSrc),
|
ignored: ignoredFiles(paths.appSrc),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||||
https: protocol === 'https',
|
https: protocol === 'https',
|
||||||
host: host,
|
host,
|
||||||
overlay: false,
|
overlay: false,
|
||||||
historyApiFallback: {
|
historyApiFallback: {
|
||||||
|
|
||||||
// Paths with dots should still use the history fallback.
|
// Paths with dots should still use the history fallback.
|
||||||
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
||||||
disableDotRule: true,
|
disableDotRule: true,
|
||||||
|
@ -84,6 +94,7 @@ module.exports = function(proxy, allowedHost) {
|
||||||
before(app) {
|
before(app) {
|
||||||
// This lets us open files from the runtime error overlay.
|
// This lets us open files from the runtime error overlay.
|
||||||
app.use(errorOverlayMiddleware());
|
app.use(errorOverlayMiddleware());
|
||||||
|
|
||||||
// This service worker file is effectively a 'no-op' that will reset any
|
// This service worker file is effectively a 'no-op' that will reset any
|
||||||
// previous service worker registered for the same host:port combination.
|
// previous service worker registered for the same host:port combination.
|
||||||
// We do this in development to avoid hitting the production cache if
|
// We do this in development to avoid hitting the production cache if
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"private": false,
|
"private": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "yarn lint:js && yarn lint:css",
|
"lint": "yarn lint:js && yarn lint:css",
|
||||||
"lint:js": "eslint src test scripts",
|
"lint:js": "eslint src test scripts config",
|
||||||
"lint:js:fix": "yarn lint:js --fix",
|
"lint:js:fix": "yarn lint:js --fix",
|
||||||
"lint:css": "stylelint src/**/*.scss",
|
"lint:css": "stylelint src/**/*.scss",
|
||||||
"lint:css:fix": "yarn lint:css --fix",
|
"lint:css:fix": "yarn lint:css --fix",
|
||||||
|
|
Loading…
Reference in a new issue