forked from cerner/f-twelve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (86 loc) · 2.38 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
require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const packageDotjson = require('./package.json');
const packageName = packageDotjson.name;
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = (env, argv) => {
const production = argv.mode === 'production';
return {
mode: argv.mode,
devtool: production ? 'source-map' : 'inline-source-map',
devServer: {
publicPath: '/',
open: true,
openPage: 'demo/index.html?dev',
proxy: {
// Serve dist from memory (not disk)
'/dist': {
target: 'http://localhost:8080',
pathRewrite: { '^/dist': '' }
}
}
},
entry: path.join(__dirname, 'src', 'main.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: `${packageName}.js`,
library: 'fTwelve',
libraryExport: 'default',
libraryTarget: 'var',
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
}),
new OptimizeCssAssetsPlugin({})
]
},
module: {
rules: [
{
test: /(\.jsx?)$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
},
{
test: /\.(s?css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: production ? '[hash:base64:5]' : '[name]_[local]_[hash:base64:5]',
context: path.resolve(__dirname, 'src')
},
},
{
loader: 'sass-loader'
}
]
}
]
},
plugins: [
production ? new CleanWebpackPlugin() : () => null, // Do not clean dist when running dev-server
new MiniCssExtractPlugin({
filename: `${packageName}.css`,
}),
],
resolve: {
extensions: ['.js', '.jsx'],
'alias': {
'preact$': production ? 'preact' : 'preact/src/index',
'preact/hooks$': production ? 'preact/hooks' : 'preact/hooks/src/index',
},
}
};
};