-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
123 lines (112 loc) · 2.58 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
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
/**
* Name of block or page to build
* @type {String}
*/
var target;
/**
* Building type `Page` or `Block`
* @type {String}
*/
var type;
/**
* Path to input file for building
* @type {String}
*/
var entry;
/**
* Output file name
* @type {String}
*/
var output;
/**
* Current environment
* @type {String}
* @default test
*/
var env = 'Test';
/**
* Parsing cmd arguments, suported are
* --block=block_name - which block to build
* --env=environment - test or product
*/
process.argv.forEach((argv) =>
{
argv = argv.split('=');
if (argv.length != 2)
{
return;
}
switch(argv[0])
{
case '--block':
target = argv[1];
output = 'Example';
entry = target + '/.Example/Example'
type = 'Block';
break;
case '--page':
target = argv[1];
output = target;
entry = target + `/${argv[1]}`;
type = 'Page';
break;
case '--env':
env = (argv[1] === 'prod') ? 'Production' : 'Test';
break;
}
});
module.exports =
{
entry: `./${type}s/${entry}.js`,
output:
{
filename: `${output}.js`,
path: path.resolve(__dirname, `./Build/${env}/${type}s/${target}`),
},
module:
{
rules:
[
{
test: /\.js$/,
use:
{
loader: 'babel-loader',
options:
{
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{ test: /\.svg$/, use: ['raw-loader'] },
{
test: /\.(png|jpe?g|gif)$/i,
loader: 'file-loader',
options:
{
publicPath: 'Assets/',
name: '[name].[ext]',
},
},
],
},
plugins:
[
new CopyPlugin([
{ from: `${type}s/${entry}.html`, to: `${output}.html` },
{ from: `${type}s/${output}/Assets`, to: 'Assets' },
{ from: `${type}s/${output}/Basis.js`, to: 'Basis.js' }
]),
new MiniCssExtractPlugin(
{ filename: `${output}.css` }
),
],
mode: 'development',
};