Skip to content

Commit 58bb621

Browse files
skipjackbebraw
authored andcommitted
refactor(config): utilize diable option in the extract plugin to simplify config
Utilizing the `ExtractTextPlugin`s `disable` prop instead of duplicating the configs. Also adding a `.postcssrc.js` which will make things easier going forward as we move to postcss and cssnext instead of sass. This also removes some code from the webpack config and isolates the postcss config which I think is a good thing.
1 parent 93a34dd commit 58bb621

File tree

3 files changed

+64
-117
lines changed

3 files changed

+64
-117
lines changed

.editorconfig

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Top-most EditorConfig file
22
root = true
33

4-
# Set default charset
5-
[*.{js}]
6-
charset = utf-8
7-
4+
# AutoFormat All Files
85
[*]
96
trim_trailing_whitespace = true
107
insert_final_newline = true
118

12-
# 4 space indentation
13-
[*.{md,js,jsx,scss,hbs}]
9+
# Format All Source Files
10+
[*.{md,js,jsx,json,scss,hbs,*rc}]
11+
charset = utf-8
1412
indent_style = space
1513
indent_size = 2
1614

17-
# Format Config
18-
[{package.json,.alexrc,babelrc,.eslintignore,.eslintrc,.markdownlint.json,.proselintrc}]
15+
# Format Any Missing Config Files
16+
[.eslintignore]
1917
indent_style = space
2018
indent_size = 2

.postcssrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: [
3+
require('autoprefixer')
4+
]
5+
}

webpack.config.js

Lines changed: 53 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ var stylePaths = [
1111
path.join(cwd, 'components')
1212
];
1313

14-
const commonConfig = {
14+
const commonConfig = env => ({
1515
resolve: {
1616
extensions: ['.js', '.jsx', '.scss']
1717
},
18+
1819
resolveLoader: {
1920
alias: {
2021
'page-loader': path.resolve(cwd, 'loaders/page-loader')
2122
}
2223
},
24+
2325
module: {
2426
rules: [
2527
{
@@ -35,6 +37,44 @@ const commonConfig = {
3537
path.join(__dirname, 'components')
3638
]
3739
},
40+
{
41+
test: /\.font.js$/,
42+
loader: ExtractTextPlugin.extract({
43+
fallback: 'style-loader',
44+
use: [
45+
'css-loader',
46+
{
47+
loader: 'fontgen-loader',
48+
options: { embed: true }
49+
}
50+
]
51+
})
52+
},
53+
{
54+
test: /\.css$/,
55+
loader: ExtractTextPlugin.extract({
56+
fallback: 'style-loader',
57+
use: 'css-loader'
58+
}),
59+
include: stylePaths
60+
},
61+
{
62+
test: /\.scss$/,
63+
loader: ExtractTextPlugin.extract({
64+
fallback: 'style-loader',
65+
use: [
66+
'css-loader',
67+
'postcss-loader',
68+
{
69+
loader: 'sass-loader',
70+
options: {
71+
includePaths: [ path.join('./styles/partials') ]
72+
}
73+
}
74+
]
75+
}),
76+
include: stylePaths
77+
},
3878
{
3979
test: /\.woff2?$/,
4080
use: {
@@ -54,13 +94,20 @@ const commonConfig = {
5494
}
5595
]
5696
},
97+
5798
plugins: [
5899
new CopyWebpackPlugin([{
59100
from: './assets',
60101
to: './assets'
61-
}])
102+
}]),
103+
104+
new ExtractTextPlugin({
105+
filename: '[chunkhash].css',
106+
allChunks: true,
107+
disable: env === 'develop'
108+
})
62109
]
63-
};
110+
});
64111

65112
const interactiveConfig = {
66113
resolve: {
@@ -78,119 +125,16 @@ const interactiveConfig = {
78125
]
79126
};
80127

81-
const developmentConfig = {
82-
module: {
83-
rules: [
84-
{
85-
test: /\.font.js$/,
86-
use: ['style-loader', 'css-loader', 'fontgen-loader']
87-
},
88-
{
89-
test: /\.css$/,
90-
use: ['style-loader', 'css-loader'],
91-
include: stylePaths
92-
},
93-
{
94-
test: /\.scss$/,
95-
use: [
96-
'style-loader',
97-
'css-loader',
98-
postcssLoader(),
99-
sassLoader()
100-
],
101-
include: stylePaths
102-
}
103-
]
104-
}
105-
};
106-
107-
const buildConfig = {
108-
module: {
109-
rules: [
110-
{
111-
test: /\.font.js$/,
112-
loader: ExtractTextPlugin.extract({
113-
fallback: 'style-loader',
114-
use: [
115-
'css-loader',
116-
{
117-
loader: 'fontgen-loader',
118-
options: {
119-
embed: true
120-
}
121-
}
122-
]
123-
})
124-
},
125-
{
126-
test: /\.css$/,
127-
loader: ExtractTextPlugin.extract({
128-
fallback: 'style-loader',
129-
use: 'css-loader'
130-
}),
131-
include: stylePaths
132-
},
133-
{
134-
test: /\.scss$/,
135-
loader: ExtractTextPlugin.extract({
136-
fallback: 'style-loader',
137-
use: [
138-
'css-loader',
139-
postcssLoader(),
140-
sassLoader()
141-
]
142-
}),
143-
include: stylePaths
144-
}
145-
]
146-
},
147-
plugins: [
148-
new ExtractTextPlugin({
149-
filename: '[chunkhash].css',
150-
allChunks: true
151-
})
152-
]
153-
};
154-
155-
function postcssLoader() {
156-
return {
157-
loader: 'postcss-loader',
158-
options: {
159-
plugins: () => ([
160-
require('autoprefixer'),
161-
])
162-
}
163-
};
164-
}
165-
166-
function sassLoader() {
167-
return {
168-
loader: 'sass-loader',
169-
options: {
170-
includePaths: [ path.join('./styles/partials') ]
171-
}
172-
};
173-
}
174-
175128
module.exports = function(env) {
176129
switch(env) {
177130
case 'develop':
178-
return merge(
179-
commonConfig,
180-
developmentConfig
181-
);
131+
case 'build':
132+
return commonConfig(env);
182133

183134
case 'interactive':
184135
return merge(
185-
commonConfig,
136+
commonConfig(env),
186137
interactiveConfig
187138
);
188-
189-
case 'build':
190-
case 'lint:links':
191-
return merge(
192-
commonConfig,
193-
buildConfig
194-
);
195139
}
196140
};

0 commit comments

Comments
 (0)