-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.lib.js
96 lines (93 loc) · 3.03 KB
/
webpack.config.lib.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 dev = process.env.NODE_ENV === 'dev';
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpackConfig = {
mode: dev ? 'development' : 'production',
// How source maps are generated : style of source mapping
devtool: dev ? 'eval-cheap-module-source-map' : false,
// Where webpack looks to start building the bundle
entry: {
lib: './src/packages/@nyaf/lib/index.ts',
forms: './src/packages/@nyaf/forms/index.ts',
store: './src/packages/@nyaf/store/index.ts'
},
optimization: {
minimize: dev ? false : true
},
// How the different types of modules within a project will be treated
module: {
rules: [
{
test: /\.ts|\.tsx$/,
loader: 'ts-loader',
options: {
configFile: 'tsconfig.webpack.json'
}
},
]
},
externals: [
'@nyaf/lib'
],
// Configure how modules are resolved
resolve: {
extensions: ['.ts', '.tsx', '.js'],
modules: [
path.resolve('./src'),
path.resolve('./src/packages'),
path.resolve('./node_modules')
],
alias: {
// modules: path.join(__dirname, 'node_modules'),
'@nyaf/lib': path.join(__dirname, 'src/packages/@nyaf/lib'),
'@nyaf/forms': path.join(__dirname, 'src/packages/@nyaf/forms'),
'@nyaf/store': path.join(__dirname, 'src/packages/@nyaf/store')
},
// plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.webpack.json" })]
},
// How and where webpack should output bundles, assets and anything else
output: {
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
filename: '@nyaf/[name]/[name].umd.js'
},
// What bundle information gets displayed
stats: {
warnings: false,
assets: false,
},
// Target a specific environment (cf. doc)
target: 'web',
// Configure whether to polyfill or mock certain Node.js globals and modules
node: {
__dirname: false
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: '**/README.md', to: '', context: 'src/packages', toType: 'dir' },
{ from: '**/package.json', to: '', context: 'src/packages', toType: 'dir' },
{ from: '**/*.d.ts', to: '@nyaf/lib', context: path.resolve(__dirname, 'out-tsc/lib') },
{ from: '**/*.d.ts', to: '@nyaf/forms', context: path.resolve(__dirname, 'out-tsc/forms') },
{ from: '**/*.d.ts', to: '@nyaf/store', context: path.resolve(__dirname, 'out-tsc/store') },
{
from: '@nyaf/cli/**/*',
context: './src/packages',
to: '',
toType: 'dir'
}
],
options: {
concurrency: 100
}
}),
]
};
if (dev) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
// Export the config
module.exports = webpackConfig;