-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
105 lines (100 loc) · 4.01 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
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = env => {
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const isLegacy = !!process.env.legacy && !(process.env.legacy == "false");
console.log(">> webpack nodeEnv=" + nodeEnv);
console.log(">> webpack isProd=" + isProd);
console.log(">> webpack isLegacy=" + isLegacy);
const presets = [
["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": 3,
"targets": {
"browsers": isLegacy ? ["defaults"] : [
"last 2 Chrome versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 Firefox versions",
"last 2 Edge versions"]
}
}],
"@babel/preset-typescript"
];
return {
entry: isLegacy ? [
path.resolve(__dirname, 'src')
] : path.resolve(__dirname, 'src'),
devtool: isProd ? false : 'source-map',
output: {
filename: isProd ? '[fullhash].bundle.js' : '[fullhash].bundle.js',
globalObject: 'this',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
mainFields: ['esm2015', 'module', 'main'],
extensions: ['.ts', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({
configFile: './tsconfig.json',
extensions: ['.ts', '.js'],
mainFields: ['esm2015', 'module', 'main']
})]
},
module: {
rules: [
{ test: /\.(png|svg|jpg|gif)$/, use: ['file-loader'] },
{ test: /\.(csv|tsv)$/, use: ['csv-loader'] },
{ test: /\.xml$/, use: ['xml-loader'] },
{ test: /\.css$/, sideEffects: true, use: ['style-loader', 'css-loader'] },
{
test: /worker\.(ts|js)$/,
use: [
{ loader: 'worker-loader' },
{
loader: 'babel-loader', options: {
"compact": isProd ? true : false,
"presets": presets,
"plugins": [
"@babel/plugin-transform-class-static-block",
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-runtime"
]
}
}
]
},
{
test: /\.(ts|js)$/, loader: 'babel-loader',
options: {
"compact": isProd ? true : false,
"presets": presets,
"plugins": [
"@babel/plugin-transform-class-static-block",
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-runtime"
]
},
exclude:
function (modulePath) {
return /node_modules/.test(modulePath) &&
!/igniteui-webcomponents/.test(modulePath) &&
!/lit-html/.test(modulePath);
}
}],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(nodeEnv)
}),
new HtmlWebpackPlugin({
title: 'for-cs',
template: 'index.html'
}),
new ForkTsCheckerWebpackPlugin()
]
};
};