-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (93 loc) · 2.78 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
/*jshint esversion: 6 */
const packageJSON = require('./package.json');
const packageName = normalizePackageName(packageJSON.name);
const LIB_NAME = pascalCase(packageName);
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
mode: "production",
devtool: "source-map",
entry: {
publicApi: './src/public_api.ts',
styles: './src/styles.less'
},
output: {
path: __dirname + '/dist',
filename: '[name].js',
libraryTarget: 'umd',
library: LIB_NAME,
// libraryExport: LIB_NAME,
// will name the AMD module of the UMD build. Otherwise an anonymous define is used.
umdNamedDefine: true,
},
optimization: {
splitChunks: {
chunks: 'all'
},
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
]
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js", ".css", ".less"]
},
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader',
options: { /* Loader options go here */
failOnHint: false
}
},
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
compilerOptions: {
// this doesn't work right now: https://github.com/Microsoft/TypeScript/issues/21443
// declaration: false,
// declarationDir: null
}
}
},
{ test: /\.css$/, loaders: [MiniCssExtractPlugin.loader, 'css-loader'] },
{ test: /\.less$/, loaders: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'] }
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css"
})
]
};
function camelCaseToDash(myStr) {
return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
function dashToCamelCase(myStr) {
return myStr.replace(/-([a-z])/g, g => g[1].toUpperCase());
}
function toUpperCase(myStr) {
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`;
}
function pascalCase(myStr) {
return toUpperCase(dashToCamelCase(myStr));
}
function normalizePackageName(rawPackageName) {
const scopeEnd = rawPackageName.indexOf('/') + 1;
return rawPackageName.substring(scopeEnd);
}