forked from master-co/css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
77 lines (75 loc) · 2.16 KB
/
webpack.prod.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
const jsConfig = require('./webpack.common.js');
const path = require('path');
const webpack = require('webpack');
const glob = require('glob');
const CopyPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const src = path.resolve('./src');
const packagePath = path.join(src, 'package.json');
const package = require(packagePath);
const master = require('./master.json');
const entries = [
...glob.sync(path.join(src, 'colors.js')),
...glob.sync(path.join(src, 'breakpoints.js')),
...glob.sync(path.join(src, 'render.ts')),
...glob.sync(path.join(src, 'index.ts')),
];
module.exports = {
entry: entries.reduce((entrypoint, eachPath) => {
const parsePath = path.parse(path.relative(src, eachPath));
const filename = path.join(parsePath.dir, parsePath.name);
if (entrypoint[filename]) {
entrypoint[filename].push(path.resolve(eachPath))
} else {
entrypoint[filename] = [path.resolve(eachPath)];
}
return entrypoint;
}, {}),
resolve: jsConfig.resolve,
externals: [
...Object.keys(package.peerDependencies || []),
...Object.keys(package.dependencies || [])
],
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
compress: {
drop_console: true
}
},
extractComments: false
}),
],
},
module: {
rules: [
...jsConfig.module.rules
]
},
output: {
clean: true,
library: {
name: '@master/css',
type: 'umd',
},
globalObject: 'this'
},
plugins: [
new webpack.ProgressPlugin(),
new CopyPlugin({
patterns: [
...master.assets.map((glob) => ({
from: glob,
noErrorOnMissing: true
}))
],
}),
...jsConfig.plugins
]
}