/
webpack.config.js
68 lines (57 loc) · 1.74 KB
/
webpack.config.js
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
'use strict';
let path = require('path');
let webpack = require('webpack');
let autoprefixer = require('autoprefixer');
let HtmlPlugin = require('html-webpack-plugin');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
const APP_TITLE = 'Big Lake';
const APP_NAME = 'big-lake';
module.exports = (env) => {
env = env || 'DEV';
let config = {};
config.entry = {};
config.entry[APP_NAME] = path.resolve(__dirname, 'src/index.js')
config.output = {
path: path.resolve(__dirname, 'build'),
filename: '[name].[hash].js'
};
if (env === 'PROD') {
config.output.publicPath = `/${APP_NAME}`;
}
config.module = {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: ['css-loader', 'postcss-loader']
})
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}
]
};
config.plugins = [
new webpack.LoaderOptionsPlugin({ options: { postcss: [ autoprefixer ] }}),
new ExtractTextPlugin('[name].[hash].css'),
new HtmlPlugin({
title: APP_TITLE,
template: path.resolve(__dirname, 'src/index.html'),
path: path.resolve(__dirname, 'build'),
inject: false
})
];
config.devServer = {
contentBase: path.resolve(__dirname, 'build'),
inline: false,
port: 9000
};
return config;
};