-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (70 loc) · 1.57 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
// user variables
const libraryName = 'AutoWriter';
// set core
const core = (env, options) => {
let isDev = options.mode === 'development';
let config = {
mode: isDev ? 'development' : 'production',
entry: './src/index.ts',
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" },
],
},
plugins: [],
};
if (isDev)
{
/**
* Development
* Open the server for testing.
*/
config.output = {
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].js',
library: libraryName,
libraryExport: 'default',
};
config.devtool = 'inline-source-map';
config.devServer = {
hot: true,
host: '0.0.0.0',
port: options.port || 4000,
stats: { color: true },
historyApiFallback: true,
noInfo: true,
contentBase: path.resolve(__dirname, 'dev'),
};
config.plugins.push(new HtmlWebpackPlugin({
template: './dev/index.html',
showErrors: true,
}));
}
else
{
/**
* Production
*/
config.output = {
filename: libraryName + '.js',
path: path.resolve(__dirname, 'dist'),
library: libraryName,
libraryTarget: 'umd',
libraryExport: 'default',
};
config.optimization = {
minimizer: [
new TerserJSPlugin({}),
],
};
}
return config;
};
module.exports = core;