-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
117 lines (113 loc) · 3.34 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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const argv = require('yargs').argv;
// const webpack = require('webpack');
const htmlMinifyOptions = {
removeComments: true,
removeAttributeQuotes: true,
collapseWhitespace: true
};
const webpackPlugins = [
new ExtractTextPlugin('[name].[chunkhash].css'),
new CopyWebpackPlugin([{
from: 'src/docs',
to: 'docs'
},
{
from: 'src/assets/favicon.ico'
},
{
from: 'About.md',
to: 'docs'
},
{
from: 'dist/data',
to: '../functions/data'
},
]),
new HtmlWebpackPlugin({
template: 'src/index.html',
minify: argv.env === 'prod' ? htmlMinifyOptions : false,
buildTime: (new Date()).toDateString(),
inject: false
})
];
if (argv.env === 'prod') {
webpackPlugins.push(new UglifyJsPlugin({
extractComments: true
}));
}
module.exports = {
entry: ['babel-polyfill', './src/index.js'],
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
path: path.resolve(__dirname, 'dist')
},
optimization: {},
externals: {
jquery: 'jQuery'
},
devServer: {
port: 9000,
contentBase: './dist',
// Proxy it via myjson api for development
proxy: {
'/data/output.json': {
target: 'https://api.myjson.com',
pathRewrite: {
'^/data/output.json': '/bins/1gqeib'
},
secure: false,
changeOrigin: true
}
}
},
module: {
rules: [{
enforce: 'pre',
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader',
}, {
test: /(\.css|\.scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
}, {
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
require('postcss-cssnext')(),
require('cssnano')({
preset: ['default', {
discardComments: {
removeAll: true,
},
}]
})
]
}
}, 'sass-loader']
})
}, {
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader']
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}]
},
plugins: webpackPlugins,
mode: argv.env === 'prod' ? 'production' : 'development'
};