Skip to content

Commit 0566761

Browse files
committed
add sass-loader
1 parent e604a19 commit 0566761

File tree

5 files changed

+13157
-8
lines changed

5 files changed

+13157
-8
lines changed

config/webpack.config.dev.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ module.exports = {
102102
'.json',
103103
'.web.jsx',
104104
'.jsx',
105+
'.scss'
105106
],
106107
alias: {
107108
// @remove-on-eject-begin
@@ -220,6 +221,44 @@ module.exports = {
220221
},
221222
],
222223
},
224+
{
225+
test: /\.scss$/,
226+
use: [
227+
require.resolve('style-loader'),
228+
{
229+
loader: require.resolve('css-loader'),
230+
options: {
231+
importLoaders: 1,
232+
},
233+
},
234+
{
235+
loader: require.resolve('postcss-loader'),
236+
options: {
237+
// Necessary for external CSS imports to work
238+
// https://github.com/facebookincubator/create-react-app/issues/2677
239+
ident: 'postcss',
240+
plugins: () => [
241+
require('postcss-flexbugs-fixes'),
242+
autoprefixer({
243+
browsers: [
244+
'>1%',
245+
'last 4 versions',
246+
'Firefox ESR',
247+
'not ie < 9', // React doesn't support IE8 anyway
248+
],
249+
flexbox: 'no-2009',
250+
}),
251+
],
252+
},
253+
},
254+
{
255+
loader: 'sass-loader',
256+
options: {
257+
includePaths: [paths.appSrc + '/styles', paths.appSrc + '/components']
258+
}
259+
}
260+
],
261+
},
223262
// "file" loader makes sure those assets get served by WebpackDevServer.
224263
// When you `import` an asset, you get its (virtual) filename.
225264
// In production, they would get copied to the `build` folder.
@@ -230,14 +269,14 @@ module.exports = {
230269
// it's runtime that would otherwise processed through "file" loader.
231270
// Also exclude `html` and `json` extensions so they get processed
232271
// by webpacks internal loaders.
233-
exclude: [/\.js$/, /\.html$/, /\.json$/],
272+
exclude: [/\.js$/, /\.html$/, /\.json$/, /\.scss$/],
234273
loader: require.resolve('file-loader'),
235274
options: {
236275
name: 'static/media/[name].[hash:8].[ext]',
237276
},
238277
},
239278
],
240-
},
279+
}
241280
// ** STOP ** Are you adding a new loader?
242281
// Make sure to add the new loader(s) before the "file" loader.
243282
],

config/webpack.config.prod.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
'.json',
110110
'.web.jsx',
111111
'.jsx',
112+
'.scss'
112113
],
113114
alias: {
114115
// @remove-on-eject-begin
@@ -246,6 +247,59 @@ module.exports = {
246247
),
247248
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
248249
},
250+
{
251+
test: /\.scss$/,
252+
loader: ExtractTextPlugin.extract(
253+
Object.assign(
254+
{
255+
fallback: {
256+
loader: require.resolve('style-loader'),
257+
options: {
258+
hmr: false,
259+
},
260+
},
261+
use: [
262+
{
263+
loader: require.resolve('css-loader'),
264+
options: {
265+
importLoaders: 1,
266+
minimize: true,
267+
sourceMap: shouldUseSourceMap,
268+
},
269+
},
270+
{
271+
loader: require.resolve('postcss-loader'),
272+
options: {
273+
// Necessary for external CSS imports to work
274+
// https://github.com/facebookincubator/create-react-app/issues/2677
275+
ident: 'postcss',
276+
plugins: () => [
277+
require('postcss-flexbugs-fixes'),
278+
autoprefixer({
279+
browsers: [
280+
'>1%',
281+
'last 4 versions',
282+
'Firefox ESR',
283+
'not ie < 9', // React doesn't support IE8 anyway
284+
],
285+
flexbox: 'no-2009',
286+
}),
287+
],
288+
},
289+
},
290+
{
291+
loader: 'sass-loader',
292+
options: {
293+
includePaths: [paths.appSrc + '/styles', paths.appSrc + '/components']
294+
}
295+
}
296+
],
297+
},
298+
extractTextPluginOptions
299+
)
300+
),
301+
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
302+
},
249303
// "file" loader makes sure assets end up in the `build` folder.
250304
// When you `import` an asset, you get its filename.
251305
// This loader doesn't use a "test" so it will catch all modules
@@ -256,7 +310,7 @@ module.exports = {
256310
// it's runtime that would otherwise processed through "file" loader.
257311
// Also exclude `html` and `json` extensions so they get processed
258312
// by webpacks internal loaders.
259-
exclude: [/\.js$/, /\.html$/, /\.json$/],
313+
exclude: [/\.js$/, /\.html$/, /\.json$/, /\.scss$/],
260314
options: {
261315
name: 'static/media/[name].[hash:8].[ext]',
262316
},

0 commit comments

Comments
 (0)