-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dll.ts
86 lines (76 loc) · 2.22 KB
/
webpack.dll.ts
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
import * as dotenv from 'dotenv';
import * as _ from 'lodash/fp';
import * as path from 'path';
import { Configuration, DllPlugin, EnvironmentPlugin } from 'webpack';
import * as autoprefixer from 'autoprefixer';
import * as MiniCSSExtractPlugin from 'mini-css-extract-plugin';
import * as OptimizeCSSPlugin from 'optimize-css-assets-webpack-plugin';
dotenv.config();
const devMode = process.env.NODE_ENV === 'development';
const dllNames: string[] = [];
const dll = (
name: string,
filename: string,
entry: string | string[],
options?: Omit<Configuration, 'entry' | 'output'>
) => {
const config = <Configuration>{
mode: devMode ? 'development' : 'production',
devtool: devMode ? 'inline-source-map' : 'source-map',
entry: {},
output: {
filename,
path: path.resolve(__dirname, 'dist/library'),
library: name,
},
stats: 'detailed',
plugins: [
new DllPlugin({
name,
context: '/',
path: path.resolve(__dirname, `dist/library/${name}.manifest.json`),
}),
],
};
config.entry![name] = entry;
options && options.plugins && config.plugins!.push(...options.plugins) && delete options.plugins;
dllNames.push(name);
return _.merge(_.cloneDeep(config), options);
};
export default <Configuration[]>[
dll('blueprint', 'blueprint.css.js', './src/library/blueprint.scss', {
plugins: [
// @ts-ignore
new MiniCSSExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css',
esModule: true,
}),
// @ts-ignore
new OptimizeCSSPlugin(),
],
module: {
rules: [
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{ test: /\.svg$/i, loader: 'svg-inline-loader' },
{
test: /\.(sa|sc|c)ss$/i,
use: [
MiniCSSExtractPlugin.loader,
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true, plugins: [autoprefixer()] } },
{ loader: 'sass-loader' },
],
},
],
},
}),
// dll('preact', 'preact'),
];
export { dllNames };