This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
forked from jenyayel/help-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (94 loc) · 2.95 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
const path = require('path');
const webpack = require('webpack');
var copyWebpackPlugin = require('copy-webpack-plugin');
const bundleOutputDir = './dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
entry: './src/index.ts',
output: {
filename: 'widget.js',
path: path.resolve(bundleOutputDir),
},
devServer: {
contentBase: bundleOutputDir
},
plugins: isDevBuild
? [new webpack.SourceMapDevToolPlugin(), new copyWebpackPlugin([{ from: 'dev/' }])]
: [],
optimization: {
minimize: !isDevBuild
},
mode: isDevBuild ? 'development' : 'production',
module: {
rules: [
// packs SVG's discovered in url() into bundle
{ test: /\.svg/, use: 'svg-url-loader' },
{
test: /\.css$/i,
use: [
{
loader: 'style-loader',
options: { injectType: 'singletonStyleTag' }
},
{
// allows import CSS as modules
loader: 'css-loader',
options: {
modules: {
// css class names format
localIdentName: '[name]-[local]-[hash:base64:5]'
},
sourceMap: isDevBuild
}
}
]
},
// use babel-loader for TS and JS modeles,
// starting v7 Babel babel-loader can transpile TS into JS,
// so no need for ts-loader
// note, that in dev we still use tsc for type checking
{
test: /\.(js|ts|tsx|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
'targets': {
'browsers': ['IE 11, last 2 versions']
},
// makes usage of @babel/polyfill because of IE11
// there is at least async functions and for..of
useBuiltIns: 'usage'
}],
[
// enable transpiling ts => js
"@babel/typescript",
// tell babel to compile JSX using into Preact
{ jsxPragma: "h" }
]
],
'plugins': [
// syntax sugar found in React components
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
// transpile JSX/TSX to JS
['@babel/plugin-transform-react-jsx', {
// we use Preact, which has `Preact.h` instead of `React.createElement`
pragma: 'h',
pragmaFrag: 'Fragment'
}]
]
}
}
]
}]
},
resolve: {
extensions: ['*', '.js', '.ts', '.tsx']
}
}];
};