-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.page.config.js
116 lines (107 loc) · 2.93 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
const process = require("process");
const path = require("path");
const fs = require('fs');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const MinifyPlugin = require("babel-minify-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: ['babel-polyfill', './src/page/index.js'],
//mode: 'production',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
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')
],
loader: 'babel-loader?cacheDirectory=true',
options: {
presets: ["@babel/preset-env"]
}
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
minimize: true
}
},
"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/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')
})
],
optimization : {
runtimeChunk : false,
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0
}
}
};
if(process.env.npm_lifecycle_script.includes('production')){
console.log('MODE: Production', process.env.npm_lifecycle_script);
delete options.devtool;
options.plugins.push(new MinifyPlugin());
}
return options;
}