-
Notifications
You must be signed in to change notification settings - Fork 183
/
webpack.config.js
116 lines (107 loc) · 3.26 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const root = pathname => path.resolve(__dirname, pathname);
const devMode = process.env.NODE_ENV !== 'production';
const excludePaths = [/node_modules/, /2014/, /2015/, /2016/, /2017/];
module.exports = {
mode: process.env.NODE_ENV,
devtool: devMode ? 'source-map' : false,
context: root('src'),
entry: {
index: root('src/js/index.js')
},
output: {
path: root('dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.html'],
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: excludePaths,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env'
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-dynamic-import'
]
}
}
},
{
test: /index\.html$/,
exclude: excludePaths,
use: [{
loader: 'html-loader',
options: {
minimize: !devMode
}
}],
},
{
test: /\.scss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
}, {
test: /\.jpe?g$|\.png$/i,
loader: 'file-loader?name=assets/[name].[ext]'
}, {
test: require.resolve('zepto'),
use: 'imports-loader?this=>window'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: root('src/index.html'),
inject: true,
cache: false,
filename: devMode ? 'index.html' : '../index.html'
}),
new webpack.DefinePlugin({
__DEV__: devMode
}),
new CopyWebpackPlugin([
{
from: './assets/**/*',
to: root('dist/')
}
]),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css'
}),
// new BrowserSyncPlugin({
// host: 'localhost',
// port: 8123,
// proxy: 'http://localhost:8080/'
// }),
// ...(
// !devMode
// ? [new webpack.LoaderOptionsPlugin({
// minimize: true,
// debug: false
// })]
// : []
// )
]
}