-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.js
68 lines (63 loc) · 1.87 KB
/
webpack.base.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
const webpack = require('webpack');
const webpackMerge = require('webpack-merge').merge;
const path = require('path');
const { author } = require('./package.json');
const ENVIRONMENT = (process.env.NODE_ENV || 'development').toLowerCase();
const IS_PRODUCTION = ENVIRONMENT === 'production';
const root = process.cwd();
const withRoot = (...fragments) => path.join(root, ...fragments);
const src = withRoot('src');
const dist = withRoot('dist', ENVIRONMENT);
// eslint-disable-next-line import/no-dynamic-require
const { name, version } = require(path.join(root, 'package.json'));
const nodeExternals = () => /^(?!@what-webook)[a-z0-9@-].+$/i;
const merge = (custom) =>
webpackMerge(
{
target: 'node',
mode: ENVIRONMENT,
devtool: `${IS_PRODUCTION ? 'nosources-' : ''}source-map`,
context: src,
entry: {
index: ['./index'],
},
output: {
path: dist,
filename: '[name].js',
publicPath: '/',
},
plugins: [
new webpack.BannerPlugin({
raw: true,
entryOnly: true,
banner: `/*! ${name}@${version} - ${author} */\n`,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENVIRONMENT),
__WEBPACK_PACKAGE_NAME__: JSON.stringify(name),
__WEBPACK_PACKAGE_VERSION__: JSON.stringify(version),
__WEBPACK_IS_PRODUCTION__: JSON.stringify(IS_PRODUCTION),
__WEBPACK_IS_DEVELOPMENT__: JSON.stringify(!IS_PRODUCTION),
}),
],
resolve: {
extensions: ['.wasm', '.js', '.jsx', '.ts', '.tsx', '.json'],
},
module: {
rules: [
{
test: /\.[tj]sx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
},
],
},
},
custom,
);
module.exports = {
merge,
nodeExternals,
withRoot,
ENVIRONMENT,
};