Skip to content

Commit d85fae3

Browse files
committed
Proper configuration of webpack
Modify output directory to build, use ExtractTextPlugin's latest example of consumption of css files. Polyfill is not needed for the css-loader, because we are not throwing the Promise not defined Error from webpack-contrib/css-loader#145
1 parent 4cedfd3 commit d85fae3

File tree

1 file changed

+46
-52
lines changed

1 file changed

+46
-52
lines changed

webpack.config.js

+46-52
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,62 @@
1-
require('es6-promise').polyfill(); // fixes https://github.com/webpack/css-loader/issues/145
2-
3-
var webpack = require('webpack');
4-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
1+
"use strict";
2+
const path = require("path");
3+
const webpack = require("webpack");
4+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
55
var Clean = require('clean-webpack-plugin');
66

7-
var siteConfig = {
7+
const cssLoaders = [
8+
{
9+
loader: "css-loader",
10+
options: {
11+
modules: true,
12+
minimize: true
13+
}
14+
},
15+
{
16+
loader: "sass-loader"
17+
}
18+
]
19+
module.exports = {
20+
context: __dirname + "/source",
821
entry: {
9-
site: [
10-
'./source/stylesheets/site.css.scss',
11-
'./source/javascripts/site.js'
22+
site: [
23+
'./stylesheets/site.scss',
24+
'./javascripts/site.js'
1225
],
1326
},
14-
15-
resolve: {
16-
root: __dirname + '/source/javascripts',
17-
},
18-
19-
output: {
20-
path: __dirname + '/.tmp/dist',
21-
filename: 'javascripts/[name].bundle.js',
22-
},
23-
2427
module: {
25-
loaders: [
26-
// Load JS
27-
{
28-
test: /source\/javascripts\/.*\.js$/,
29-
exclude: /node_modules|\.tmp|vendor/,
30-
loader: 'babel-loader',
31-
query: {
32-
presets: ['es2015', 'stage-0']
33-
},
34-
},
35-
// Load SCSS
28+
rules: [
3629
{
37-
test: /\.scss$/,
38-
loader: ExtractTextPlugin.extract(
39-
"style",
40-
"css!sass?sourceMap"
41-
)
30+
test: /\.js$/,
31+
exclude: /(node_modules)/,
32+
loader: "babel-loader",
4233
},
43-
44-
// Embed small pngs as data uri
45-
// url-loader falls back to file-loader when image is too big
4634
{
47-
test: /\.(jpe?g|png|gif|svg)$/i,
48-
loader: "url-loader?limit=100000&name=../images/[name].[ext]"
35+
test: /\.(sass|scss)$/,
36+
use: ExtractTextPlugin.extract({
37+
fallback: "style-loader",
38+
use: "css-loader"
39+
})
4940
},
50-
],
51-
},
52-
53-
sassLoader: {
54-
includePaths: [require('bourbon').includePaths]
41+
],//end rules
5542
},
56-
57-
node: {
58-
console: true
43+
output: {
44+
path: __dirname + "/build/",
45+
filename: "[name].bundle.js",
5946
},
6047

6148
plugins: [
62-
new Clean(['.tmp']),
63-
new ExtractTextPlugin("stylesheets/site.bundle.css"),
64-
new webpack.optimize.CommonsChunkPlugin("site", "javascripts/site.bundle.js"),
49+
new Clean(['.build']),
50+
new webpack.LoaderOptionsPlugin({
51+
minimize: true,
52+
debug: false
53+
}),
54+
new ExtractTextPlugin({
55+
filename: (getPath) => {
56+
return getPath("[name].bundle.css").replace("css/js", "css");
57+
},
58+
disable: false,
59+
allChunks: true,
60+
}),
6561
],
6662
};
67-
68-
module.exports = siteConfig;

0 commit comments

Comments
 (0)