/
webpack.config.js
112 lines (98 loc) · 2.4 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
const path = require('path');
const getOutput = () => {
const output = {
filename: 'index.js',
path: path.resolve(__dirname, './dist'),
libraryTarget: 'commonjs',
};
if (process.env.TARGET === 'browser') {
output.filename = 'browser.js';
}
if (process.env.TARGET === 'cdn') {
output.filename = 'scribbletune.js';
output.library = 'scribble';
output.libraryTarget = 'umd';
}
if (process.env.TARGET === 'max') {
output.filename = 'max.js';
}
return output;
};
const getEntry = () => {
let main = './src/index.ts';
if (process.env.TARGET === 'browser' || process.env.TARGET === 'cdn') {
main = './src/browser-index.ts';
}
if (process.env.TARGET === 'max') {
main = './src/max-index.ts';
}
return {
main,
};
};
const plugins = [];
plugins.push(new DtsBundlePlugin());
// Use function to access command-line arguments:
module.exports = (env, argv) => {
const isDevelopment = argv.mode === 'development';
const isProduction = argv.mode === 'production';
return {
// mode: 'production',
entry: getEntry(),
output: getOutput(),
devtool: 'source-map', // ? process.env.TARGET === 'cdn' ? 'source-map' : '',
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
use: [
{
loader: 'eslint-loader',
options: {
fix: isProduction,
emitWarning: isDevelopment,
failOnWarning: isProduction,
configFile: '.eslintrc',
},
},
],
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {},
},
],
},
],
},
resolve: {
extensions: ['.ts', '.js', '.json'],
},
plugins: plugins,
// node: {
// fs: 'empty',
// },
externals: {
fs: 'fs',
},
};
};
function DtsBundlePlugin() {}
DtsBundlePlugin.prototype.apply = function (compiler) {
// compiler.plugin('done', function() { // webpack v4
compiler.hooks.done.tap('DtsBundlePlugin', function () {
// webpack v5
var dts = require('dts-bundle');
dts.bundle({
name: 'scribbletune',
main: 'lib/index.d.ts',
out: '../dist/index.d.ts',
removeSource: true,
outputAsModuleFolder: true, // to use npm in-package typings
});
});
};