forked from pictograpi/draw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.conf.js
More file actions
94 lines (87 loc) · 2.16 KB
/
Copy pathwebpack.conf.js
File metadata and controls
94 lines (87 loc) · 2.16 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const BabiliPlugin = require("babili-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const webpack = require("webpack");
const DEFAULT_CONFIG = {
entry: ["./src/index.js", "./src/style.scss"],
output: {
path: path.resolve(__dirname, "public"),
filename: "[name].js"
},
plugins: [
new Dotenv({
systemvars: true
}),
new CleanWebpackPlugin(["public"], {
root: path.resolve(__dirname),
verbose: true,
dry: false
}),
new HtmlWebpackPlugin({
title: "Pictograpi Draw",
hash: true,
template: "./src/index.ejs"
}),
new ExtractTextPlugin("[name].css")
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader", "eslint-loader"]
},
{
test: /\.(woff|woff2|eot|ttf|otf|png|jpg|svg)$/,
use: ["file-loader"]
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: [
"css-loader?sourceMap",
"resolve-url-loader",
"sass-loader?sourceMap",
"import-glob-loader"
],
fallback: "style-loader"
})
}
]
}
};
module.exports = (process.env.DEVELOPMENT && createDev()) || createBuild();
/**
* Creates dev configuration.
*
* @returns {Object} Webpack configuration
*/
function createDev() {
let config = Object.assign({}, DEFAULT_CONFIG);
config.devtool = "inline-source-map";
config.devServer = {
contentBase: path.join(__dirname, "public"),
compress: true,
port: 8080,
historyApiFallback: true
};
return config;
}
/**
* Craetes build configuration.
*
* @returns {Object} Webpack configuration
*/
function createBuild() {
let config = Object.assign({}, DEFAULT_CONFIG);
config.plugins.push(new BabiliPlugin());
config.plugins.push(
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
})
);
return config;
}