This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
138 lines (131 loc) · 3.87 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const resolve = require('path').resolve;
const pkg = require('./package.json');
const webpack = require('webpack');
const fs = require('fs');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const now = new Date();
const prefix = (n) => n < 10 ? ('0' + n) : n.toString();
const buildId = `${now.getUTCFullYear()}${prefix(now.getUTCMonth() + 1)}${prefix(now.getUTCDate())}-${prefix(now.getUTCHours())}${prefix(now.getUTCMinutes())}${prefix(now.getUTCSeconds())}`;
pkg.version = pkg.version.replace('SNAPSHOT', buildId);
const year = (new Date()).getFullYear();
const banner = '/*! ' + (pkg.title || pkg.name) + ' - v' + pkg.version + ' - ' + year + '\n' +
(pkg.homepage ? '* ' + pkg.homepage + '\n' : '') +
'* Copyright (c) ' + year + ' ' + pkg.author.name + ';' +
' Licensed ' + pkg.license + '*/\n';
/**
* generate a webpack configuration
*/
module.exports = (env) => {
const tsLoader = [{
loader: 'cache-loader'
},
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
configFile: env === 'dev' ? 'tsconfig_dev.json' : 'tsconfig.json',
happyPackMode: true // IMPORTANT! use happyPackMode mode to speed-up compilation and reduce errors reported to webpack
}
}
];
if (process.env.CI) {
tsLoader.splice(0, 2); // just the loader no optimization
}
return {
entry: {
'lineup-element': './src/index.ts'
},
output: {
path: resolve(__dirname, 'build'),
filename: `[name].js`,
chunkFilename: '[chunkhash].js',
publicPath: '', //no public path = relative
library: 'LineUpJS',
libraryTarget: 'umd',
umdNamedDefine: false //anonymous require module
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
symlinks: false
},
plugins: [
new webpack.BannerPlugin({
banner: banner,
raw: true
}),
//define magic constants that are replaced
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pkg.version),
__LICENSE__: JSON.stringify(pkg.license),
__BUILD_ID__: JSON.stringify(buildId)
}),
new ExtractTextPlugin({
filename: `[name].css`
}),
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true
}),
new CopyWebpackPlugin([{
from: './node_modules/lineupjs/build/*.+(svg|eot|ttf)',
flatten: true
}])
],
externals: {},
module: {
rules: [{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.tsx?$/,
use: tsLoader
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader',
options: {
limit: 20000 //inline <= 10kb
}
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 20000, //inline <= 20kb
mimetype: 'application/font-woff'
}
},
{
test: /\.svg(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 10000, //inline <= 10kb
mimetype: 'image/svg+xml'
}
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
},
watchOptions: {
ignored: /node_modules/
},
devServer: {
contentBase: 'demo'
}
};
};