-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.page.config.js
147 lines (138 loc) · 3.94 KB
/
webpack.page.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const process = require("process");
const path = require("path");
const fs = require('fs');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DIST_FOLDER = path.resolve('build', 'dist', 'page');
const DIST_DIR = path.resolve(__dirname, DIST_FOLDER);
function resolvePath(dir) {
return path.join(__dirname, dir);
}
function cleanDistFolder(directory) {
try {
let files = fs.readdirSync(directory)
for (const file of files) {
fs.unlinkSync(path.join(directory, file))
}
} catch (err) {
console.error(err);
}
}
module.exports = env => {
cleanDistFolder(DIST_FOLDER);
let options = {
entry: ['./src/page/index.js'],
//mode: 'production',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ["@babel/preset-env", "@babel/preset-react"],
}
}
]
},
{
test: /\.js$/,
include: [
resolvePath('node_modules/framework7'),
resolvePath('node_modules/framework7-react'),
resolvePath('node_modules/template7'),
resolvePath('node_modules/dom7'),
resolvePath('node_modules/ssr-window')
],
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ["@babel/preset-env", "@babel/preset-react"],
}
}
]
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
}
},
"css-loader"
]
},
{
test: /\.(pdf|jpg|png|gif|svg|ico)$/,
use: [
{
loader: 'url-loader'
},
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: DIST_DIR,
publicPath: './dist/page/',
filename: "[name].[contenthash].js"
},
plugins: [
new MiniCssExtractPlugin({ filename: 'page-style.css' }),
new HtmlWebpackPlugin({
title: 'Extension App',
template: 'src/page/index.html',
meta: {
'viewport': 'width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover',
'theme-color': '#000000'
},
filename: path.resolve(__dirname, 'build', 'index.html')
}),
new HtmlWebpackPlugin({
title: 'Next Round Page',
template: 'src/nextround.html',
meta: {
'viewport': 'width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover',
'theme-color': '#000000'
},
filename: path.resolve(__dirname, 'build', 'nextround.html'),
chunks: [], // don't automatically add any js to the base page
})
],
optimization: {
runtimeChunk : false,
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0
},
minimizer: [
new CssMinimizerPlugin(),
],
},
performance: {
// ignore warnings for sizes if not minified
maxAssetSize: 1000000,
maxEntrypointSize: 1000000,
}
};
if(process.env.npm_lifecycle_script.includes('production')){
console.log('MODE: Production', process.env.npm_lifecycle_script);
delete options.devtool;
options.plugins.push(new TerserPlugin()); //enable to minify output
}
return options;
}