-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
72 lines (69 loc) · 2 KB
/
webpack.config.js
File metadata and controls
72 lines (69 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const paths = {
ROOT: path.resolve(__dirname),
DIST: path.resolve(__dirname, 'dist'),
SRC: path.resolve(__dirname, 'src'),
// SASS: path.resolve(__dirname, 'src/sass'),
};
const files = {
INDEX_JS: path.join(paths.SRC, 'app.jsx'),
INDEX_HTML: 'dist/index.html',
MAIN_SCSS: path.join(paths.SRC, 'index.scss'),
BUNDLE: 'bundle.js',
DIST_CSS: 'dist/styles.css',
};
// Webpack configs
module.exports = {
entry: [files.INDEX_JS, files.MAIN_SCSS],
output: {
path: paths.DIST,
// TODO: make this app.bundle.js to be more clear
filename: files.BUNDLE,
},
devtool: 'eval-source-map',
// Loaders configs
// Babel Loaders
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
// Important to note, from http://bit.ly/2zoKnrv
// There needs to be a loader option somewhere
// This is inspite of the articles
// Then also, 'babel-loader' instead of 'babel' is needed
loader: 'babel-loader',
query: {
presets: ['es2015', 'react'],
},
},
// TODO: Figure out how to properly extract regular css as loader
// { // regular css files
// test: /\.css$/,
// loader: ExtractTextPlugin.extract({
// loader: 'css-loader?importLoaders=1',
// }),
// },
{ // sass / scss loader for webpack
test: /\.(sass|scss)$/,
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']),
},
],
},
// Tell Webpack to use html & CSS extract text plugin
plugins: [
new ExtractTextPlugin({ // define where to save the file
filename: files.DIST_CSS,
allChunks: true,
}),
new HtmlWebpackPlugin({
template: files.INDEX_HTML,
}),
],
// Enable importing JS files without specifying their extensions
resolve: {
extensions: ['.js', '.jsx'],
},
};