-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwebpack.config.js
129 lines (123 loc) · 2.85 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const fs = require('fs-extra');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
/*const ExtractTextPlugin = require('extract-text-webpack-plugin');*/
const srcDir = path.resolve(__dirname, 'src');
const config = {
entry: {
app: path.resolve(srcDir, 'js', 'main.js')
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devServer: {
contentBase: false,
compress: true,
historyApiFallback: true,
open: false
},
module: {
rules: [{
include: path.resolve(srcDir, 'js'),
use: [{
loader: 'babel-loader',
query: {
presets: ['env']
}
}]
},{
/* Polyfills shouldn't be merged with app.js, resolve them with an url */
include: path.resolve(srcDir, 'js', 'polyfill'),
use: [{
loader: 'file-loader',
options: {
outputPath: 'polyfill/',
name: '[name].[ext]'
}
}]
},{
include: path.resolve(srcDir, 'img'),
use: [{
loader: 'file-loader',
options: {
outputPath: 'img/',
name: '[name].[ext]'
}
}]
},{
include: path.resolve(srcDir, 'audio'),
use: [{
loader: 'file-loader',
options: {
outputPath: 'audio/',
name: '[name].[ext]'
}
}]
},{
include: path.resolve(srcDir, 'font'),
use: [{
loader: 'file-loader',
options: {
outputPath: 'font/',
name: '[name].[ext]'
}
}]
},{
include: path.resolve(srcDir, 'css'),
use: [{
loader: 'css-loader',
options: {
/*root: '..',*/
importLoaders: 1
}
},{
loader: 'postcss-loader'
}]/*ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader']
})*/
}]
},
plugins: [
new CopyWebpackPlugin([{from: 'static'}]),
/*new webpack.optimize.CommonsChunkPlugin({
name: 'libs',
filename: 'libs.js',
minChunks: module => module.context && module.context.indexOf('node_modules') !== -1
}),*/
new HtmlWebpackPlugin({
title: 'World of Pixels',
inject: 'head',
template: path.resolve(srcDir, 'index.ejs'),
favicon: path.resolve(srcDir, 'favicon.ico')
}),
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'async'
})/*,
new ExtractTextPlugin({
filename: 'css/styles.css'
})*/
]
};
module.exports = async env => {
env = env || {};
if (!env.release) {
config.mode = "development";
config.devtool = "source-map";
config.output.publicPath = '/';
} else {
config.mode = "production";
config.output.filename = '[name].[hash].js';
console.log(`Cleaning build dir: '${config.output.path}'`);
await fs.remove(config.output.path);
}
config.plugins.push(new webpack.DefinePlugin({
'PRODUCTION_BUILD': JSON.stringify(!!env.release)
}));
return config;
};