This commit is contained in:
MICHAEL JACKSON
2017-11-25 21:19:55 -08:00
parent 758b420297
commit 51f3bca3fb
13 changed files with 476 additions and 448 deletions

View File

@ -1,46 +1,44 @@
'use strict';
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ManifestPlugin = require('webpack-manifest-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
var paths = require('./paths');
var getClientEnvironment = require('./env');
"use strict"
var autoprefixer = require("autoprefixer")
var webpack = require("webpack")
var HtmlWebpackPlugin = require("html-webpack-plugin")
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var ManifestPlugin = require("webpack-manifest-plugin")
var InterpolateHtmlPlugin = require("react-dev-utils/InterpolateHtmlPlugin")
var paths = require("./paths")
var getClientEnvironment = require("./env")
// 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.
var publicPath = paths.servedPath;
var publicPath = paths.servedPath
// Some apps do not use client-side routing with pushState.
// For these, "homepage" can be set to "." to enable relative asset paths.
var shouldUseRelativeAssetPaths = publicPath === './';
var shouldUseRelativeAssetPaths = publicPath === "./"
// `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.
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
var publicUrl = publicPath.slice(0, -1);
var publicUrl = publicPath.slice(0, -1)
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl);
var env = getClientEnvironment(publicUrl)
// Assert this just to be safe.
// Development builds of React are slow and not intended for production.
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
throw new Error('Production builds must have NODE_ENV=production.');
if (env.stringified["process.env"].NODE_ENV !== '"production"') {
throw new Error("Production builds must have NODE_ENV=production.")
}
// Note: defined here because it will be used more than once.
const cssFilename = '_static/css/[name].[contenthash:8].css';
const cssFilename = "_static/css/[name].[contenthash:8].css"
// ExtractTextPlugin expects the build output to be flat.
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
// 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.
const extractTextPluginOptions = shouldUseRelativeAssetPaths
// Making sure that the publicPath goes back to to build folder.
? { publicPath: Array(cssFilename.split('/').length).join('../') }
: undefined;
? // Making sure that the publicPath goes back to to build folder.
{ publicPath: Array(cssFilename.split("/").length).join("../") }
: undefined
// This is the production configuration.
// It compiles slowly and is focused on producing a fast and minimal bundle.
@ -50,20 +48,17 @@ module.exports = {
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: 'source-map',
devtool: "source-map",
// In production, we only want to load the polyfills and the app code.
entry: [
require.resolve('./polyfills'),
paths.appIndexJs
],
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',
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
},
@ -78,21 +73,21 @@ module.exports = {
// 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
extensions: ['.js', '.json', '.jsx', ''],
extensions: [".js", ".json", ".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'
"react-native": "react-native-web"
}
},
module: {
// First, run the linter.
// It's important to do this before Babel processes the JS.
preLoaders: [
{
test: /\.(js|jsx)$/,
loader: 'eslint',
loader: "eslint",
include: paths.appSrc
}
],
@ -106,26 +101,18 @@ module.exports = {
// "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
// Otherwise, it acts like the "file" loader.
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/,
/\.md$/
],
loader: 'url',
exclude: [/\.html$/, /\.(js|jsx)$/, /\.css$/, /\.json$/, /\.svg$/, /\.md$/],
loader: "url",
query: {
limit: 10000,
name: '_static/media/[name].[hash:8].[ext]'
name: "_static/media/[name].[hash:8].[ext]"
}
},
// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
loader: "babel"
},
// The notation here is somewhat confusing.
// "postcss" loader applies autoprefixer to our CSS.
@ -142,8 +129,8 @@ module.exports = {
{
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style',
'css?importLoaders=1!postcss',
"style",
"css?importLoaders=1!postcss",
extractTextPluginOptions
)
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
@ -152,38 +139,38 @@ module.exports = {
// allow it implicitly so we also enable it.
{
test: /\.json$/,
loader: 'json'
loader: "json"
},
// "file" loader for svg
{
test: /\.svg$/,
loader: 'file',
loader: "file",
query: {
name: '_static/media/[name].[hash:8].[ext]'
name: "_static/media/[name].[hash:8].[ext]"
}
},
// HTML loader for Markdown files.
{
test: /\.md$/,
loader: 'html!markdown'
loader: "html!markdown"
}
// ** STOP ** Are you adding a new loader?
// Remember to add the new extension(s) to the "url" loader exclusion list.
]
},
// We use PostCSS for autoprefixing only.
postcss: function() {
return [
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9" // React doesn't support IE8 anyway
]
}),
];
})
]
},
plugins: [
// Makes some environment variables available in index.html.
@ -238,14 +225,14 @@ module.exports = {
// to their corresponding output file so that tools can pick it up without
// having to parse `index.html`.
new ManifestPlugin({
fileName: 'asset-manifest.json'
fileName: "asset-manifest.json"
})
],
// 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: {
fs: 'empty',
net: 'empty',
tls: 'empty'
fs: "empty",
net: "empty",
tls: "empty"
}
};
}