Skip to content

Commit

Permalink
fix(webpack.config): added missing loader for images and removed dead…
Browse files Browse the repository at this point in the history
… code.
  • Loading branch information
halfzebra committed Aug 6, 2018
1 parent 7c6a0b5 commit 106592a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
62 changes: 32 additions & 30 deletions config/webpack.config.dev.js
Expand Up @@ -19,21 +19,6 @@ const publicUrl = '';
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
const postCSSLoaderOptions = {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
flexbox: 'no-2009'
})
]
};

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
Expand Down Expand Up @@ -99,7 +84,6 @@ module.exports = {
},
module: {
noParse: /\.elm$/,

strictExportPresence: true,
rules: [
// Disable require.ensure as it's not a standard language feature.
Expand Down Expand Up @@ -206,8 +190,7 @@ module.exports = {
// in development "style" loader enables hot editing of CSS.
// By default we support CSS Modules with the extension .module.css
{
test: /\.css$/,
exclude: /\.module\.css$/,
test: /\.css/,
use: [
require.resolve('style-loader'),
{
Expand All @@ -216,23 +199,42 @@ module.exports = {
importLoaders: 1
}
},
// "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 be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/\.(js|elm)$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
loader: require.resolve('postcss-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]'
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
flexbox: 'no-2009'
})
]
}
}
]
},

{
exclude: [/\.html$/, /\.js$/, /\.elm$/, /\.css$/, /\.json$/, /\.svg$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
},

// "file" loader for svg
{
test: /\.svg$/,
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
},
Expand Down
29 changes: 12 additions & 17 deletions config/webpack.config.prod.js
Expand Up @@ -24,21 +24,6 @@ const publicUrl = publicPath.slice(0, -1);
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
const postCSSLoaderOptions = {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
flexbox: 'no-2009'
})
]
};

// Enable users to turn on dead code elimination.
const deadCodeElimination =
process.env.DEAD_CODE_ELIMINATION === 'true'
Expand Down Expand Up @@ -255,7 +240,17 @@ module.exports = {
},
{
loader: require.resolve('postcss-loader'),
options: postCSSLoaderOptions
options: {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
flexbox: 'no-2009'
})
]
}
}
]
},
Expand Down Expand Up @@ -312,7 +307,7 @@ module.exports = {
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
}),
// 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
Expand Down

0 comments on commit 106592a

Please sign in to comment.