Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Commit

Permalink
Use mini-css-extract instead of extract-text-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
diondirza committed Mar 17, 2018
1 parent 2c80f0a commit 5a6df5c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
22 changes: 11 additions & 11 deletions internal/webpack/configFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import appRootDir from 'app-root-dir';
import AssetsPlugin from 'assets-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import nodeExternals from 'webpack-node-externals';
import path from 'path';
Expand Down Expand Up @@ -66,6 +66,9 @@ export default function webpackConfigFactory(buildOptions) {
let webpackConfig = {
// Webpack Mode
mode: ifDev('development', 'production'),
// Add context for resolving entry points and loaders from configuration
// it is recommended to define the context
context: appRootDir.get(),
// Define our entry chunks for our bundle.
entry: {
// We name our entry files "index" as it makes it easier for us to
Expand Down Expand Up @@ -331,9 +334,9 @@ export default function webpackConfigFactory(buildOptions) {
// CSS files.
ifProdClient(
() =>
new ExtractTextPlugin({
filename: '[name]-[contenthash].css',
allChunks: true,
new MiniCssExtractPlugin({
filename: '[name]-[chunkhash].css',
chunkFilename: '[name]-[chunkhash].css',
}),
),

Expand Down Expand Up @@ -484,16 +487,13 @@ export default function webpackConfigFactory(buildOptions) {
// an ExtractTextPlugin instance.
// Note: The ExtractTextPlugin needs to be registered within the
// plugins section too.
ifProdClient(() => ({
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader'],
}),
})),
ifProdClient({
use: [MiniCssExtractPlugin.loader, 'css-loader'],
}),
// When targetting the server we use the "/locals" version of the
// css loader, as we don't need any css files for the server.
ifNode({
loaders: ['css-loader/locals'],
use: ['css-loader/locals'],
}),
),
),
Expand Down
56 changes: 27 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"eslint-plugin-import": "2.9.0",
"eslint-plugin-jsx-a11y": "6.0.3",
"eslint-plugin-react": "7.7.0",
"extract-text-webpack-plugin": "4.0.0-beta.0",
"file-loader": "1.1.11",
"glob": "7.1.2",
"happypack": "5.0.0-beta.1",
Expand All @@ -122,6 +121,7 @@
"jest": "22.4.2",
"lint-staged": "7.0.0",
"md5": "2.2.1",
"mini-css-extract-plugin": "0.2.0",
"modernizr-loader": "1.0.1",
"node-notifier": "5.2.1",
"prettier": "1.11.1",
Expand All @@ -133,7 +133,7 @@
"request": "2.85.0",
"rimraf": "2.6.2",
"semver": "5.5.0",
"source-map-support": "0.5.3",
"source-map-support": "0.5.4",
"style-loader": "0.20.3",
"webpack": "4.1.1",
"webpack-bundle-analyzer": "2.11.1",
Expand Down
4 changes: 3 additions & 1 deletion shared/components/DemoApp/AsyncCounterRoute/CounterRoute.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable react/no-unescaped-entities */
import React, { Component } from 'react';

import './styles.css';

class CounterRoute extends Component {
constructor(props) {
super(props);
Expand All @@ -15,7 +17,7 @@ class CounterRoute extends Component {
render() {
return (
<div>
<h3>Counter</h3>
<h3 className="counter__title">Counter</h3>
<p>
<em>
This is a small demo component that contains state. It's useful for
Expand Down
3 changes: 3 additions & 0 deletions shared/components/DemoApp/AsyncCounterRoute/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.counter__title {
color: #9b4dca;
}

0 comments on commit 5a6df5c

Please sign in to comment.