-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.config.js
71 lines (70 loc) · 2.15 KB
/
webpack.production.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
const path = require('path')
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const appDir = path.join(__dirname, '/src/app/')
const envProd = new webpack.DefinePlugin({ __DEV__: false })
const buildType = process.env.BUILD_TYPE || 'web'
const plugins = [
envProd,
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css'
}),
new HtmlWebpackPlugin({
template: path.join(appDir, 'index.ejs'),
templateParameters: {
type: buildType
},
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
html5: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeComments: true,
removeEmptyAttributes: true
},
hash: true
})
]
if (buildType === 'fbinstant') {
plugins.push(new CopyPlugin([
{ from: path.join(__dirname, 'fbapp-config.json'), to: path.resolve(__dirname, 'build_' + buildType), force: true }
]))
}
module.exports = {
mode: 'production',
entry: { app: path.join(appDir, 'index.js') },
output: {
path: path.resolve(__dirname, 'build_' + buildType),
pathinfo: true,
library: '[name]',
libraryTarget: 'umd',
filename: '[name].[chunkhash].js'
},
plugins,
optimization: { minimize: true },
module: {
rules: [{
test: /\.css$/,
use: [ { loader: MiniCssExtractPlugin.loader }, { loader: 'css-loader', options: { importLoaders: 1 } }, 'postcss-loader' ]
}, {
test: /\.js$/,
use: [ 'babel-loader' ]
}, {
test: /\.(woff(2)?|ttf|eot)?$/,
use: [{ loader: 'file-loader', options: { name: '[name].[hash].[ext]', outputPath: 'fonts' } }]
}, {
test: /\.(ogg|mp3)?$/,
use: [{ loader: 'file-loader', options: { name: '[name].[hash].[ext]', outputPath: 'sounds' } }]
}, {
test: /\.(png|jpg|svg)$/,
use: [{ loader: 'file-loader', options: { name: '[name].[hash].[ext]', outputPath: 'images' } }]
}]
}
}