forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-base.config.js
50 lines (44 loc) · 1.96 KB
/
webpack-base.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
'use strict';
const path = require('path');
const createWebpackConfigCommon = require('../../shared/webpack-base.config');
module.exports = function createWebpackConfig({ env, argv, projectRoot, configOverride }) {
// Example: "@my-company/my-library"
const packageName = require(path.join(projectRoot, 'package.json')).name;
// Example: "my-library"
const packageNameWithoutScope = packageName.split('/').pop();
// Documentation: https://webpack.js.org/configuration/
const libraryOverrides = {
target: ['web', 'es5'],
entry: {
// Rush Stack convention is that the entry point for libraries is "src/index.ts"
// whereas the entry point for apps is "src/start.ts"
[packageNameWithoutScope]: path.resolve(projectRoot, 'lib', 'index.js')
},
output: {
// For libraries, the filename is unhashed so that the package.json "main" field can refer to it
filename: `[name].js`,
library: {
// Use the full package name as the module-id name for AMD
amd: packageName
},
libraryTarget: 'umd',
// https://webpack.js.org/configuration/output/#outputlibraryumdnameddefine
// Give the amd module a globally unique id so that non AMD aware bundlers can concatenate the module
umdNamedDefine: true,
// From: https://webpack.js.org/configuration/output/#outputglobalobject
// To make UMD build available on both browsers and Node.js, set output.globalObject option to 'this'
globalObject: 'this'
},
devtool: 'source-map'
};
return createWebpackConfigCommon({
env: env,
argv: argv,
projectRoot: projectRoot,
// "If you're building a design system or component library and shipping to NPM you shouldn't
// extract just yet, let your consumers do it in their app."
// https://compiledcssinjs.com/docs/css-extraction-webpack
extractCssInProduction: false,
configOverride: createWebpackConfigCommon.merge(libraryOverrides, configOverride)
});
};