-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
130 lines (127 loc) · 3.47 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
130
const webpack = require('webpack')
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const mainJSPath = path.resolve(__dirname, './src', 'main.js')
const mainCSSPath = path.resolve(__dirname, './src', 'main.css')
const imagesPath = path.resolve(__dirname, './src/images')
// const fontsPath = path.resolve(__dirname, './src/fonts')
const publicPath = path.resolve(__dirname, './templates/assets')
const WebpackShellPlugin = require('webpack-shell-plugin')
module.exports = {
entry: {
main: [
mainJSPath,
mainCSSPath
] // ,
// vendor: []
},
devServer: {
contentBase: path.join(__dirname, 'templates'),
compress: true,
port: 9000
},
output: {
filename:
process.env.NODE_ENV === 'prod'
? 'scripts/[name].min.js?h=[hash]'
: 'scripts/[name].js?h=[hash]',
path: publicPath,
publicPath: '/assets/'
},
optimization: {
splitChunks: {
chunks: 'all'
}
},
plugins: [
new WebpackShellPlugin({
onBuildStart: ['echo "Starting"'],
onBuildEnd: ['cp -R ./templates/assets ./templates/mainnet/',
'cp -R ./templates/assets ./templates/testnet/',
'rm -rf ./templates/assets']
}),
// new webpack.optimize.AggressiveSplittingPlugin(js_split_options),
new webpack.ProvidePlugin({
// $: 'jquery',
// jQuery: 'jquery',
// objectFitImages: 'object-fit-images'
}),
new CleanWebpackPlugin(
{
dry: false,
verbose: true,
cleanStaleWebpackAssets: false
}
),
// Simply copy assets to dist folder
new CopyWebpackPlugin([
{ from: imagesPath, to: 'images' }
// { from: fontsPath, to: 'fonts' }
]),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/mainnet/index.html'),
filename: path.resolve(__dirname, './templates/mainnet/index.html'),
hash: true,
inject: true
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/testnet/index.html'),
filename: path.resolve(__dirname, './templates/testnet/index.html'),
hash: true,
inject: true
}),
new MiniCssExtractPlugin({
filename: 'styles/main.css?h=[hash]',
fallback: 'style-loader',
ignoreOrder: false
})
],
resolve: {
alias: {
// styles: path.resolve(__dirname, '../src/sass'), // relative to the location of the webpack config file!
}
},
module: {
rules: [
// ES2015 to ES5 compilation
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'standard-loader?error=true'
}
]
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: 'public/styles',
hmr: process.env.NODE_ENV === 'dev'
}
},
'css-loader',
{
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js'
}
}
}
]
}
]
}
}