forked from okta/okta-signin-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.config.js
105 lines (96 loc) · 3.38 KB
/
webpack.common.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
/* global module __dirname */
var path = require('path');
var SRC = path.resolve(__dirname, 'src');
var TARGET_JS = path.resolve(__dirname, 'target/js/');
var LOCAL_PACKAGES = path.resolve(__dirname, 'packages/');
// Return a function so that all consumers get a new copy of the config
module.exports = function (outputFilename) {
return {
entry: [`${SRC}/widget/OktaSignIn.js`],
devtool: 'source-map',
output: {
path: TARGET_JS,
filename: outputFilename,
library: 'OktaSignIn',
libraryTarget: 'umd'
},
resolve: {
modules: [SRC, 'packages', 'node_modules'],
alias: {
// General remapping
'nls': '@okta/i18n/src/json',
'okta': `${LOCAL_PACKAGES}/@okta/courage-dist/okta.js`,
'okta-i18n-bundles': 'util/Bundles',
'jquery': `${LOCAL_PACKAGES}/@okta/courage-dist/jquery.js`,
'idx': `${LOCAL_PACKAGES}/@okta/idx-dist/idx.js`,
// Vendor files from courage that are remapped in OSW to point to an npm
// module in our package.json dependencies
'handlebars/runtime': 'handlebars/dist/cjs/handlebars.runtime',
'handlebars$': 'handlebars/dist/cjs/handlebars.runtime',
'qtip': '@okta/qtip2/dist/jquery.qtip.min.js',
'duo': 'duo_web_sdk/index.js',
'typingdna': 'TypingDnaRecorder-JavaScript/typingdna',
}
},
module: {
rules: [
// Babel
{
test: /\.js$/,
// exclude: function (filePath) {
// const filePathContains = (f) => filePath.indexOf(f) > 0;
// const npmRequiresTransform = [
// '/node_modules/parse-ms',
// '/node_modules/@sindresorhus/to-milliseconds'
// ].some(filePathContains);
// const shallBeExcluded = [
// '/node_modules/',
// 'packages/@okta/courage-dist/jquery.js',
// 'packages/@okta/qtip2'
// ].some(filePathContains);
// return shallBeExcluded && !npmRequiresTransform;
// },
exclude: function (filePath) {
const filePathContains = (f) => filePath.indexOf(f) > 0;
const s = path.sep;
const npmRequiresTransform = [
`${s}node_modules${s}parse-ms`,
`${s}node_modules${s}@sindresorhus${s}to-milliseconds`
].some(filePathContains);
const shallBeExcluded = [
`${s}node_modules${s}`,
`packages${s}@okta${s}courage-dist${s}jquery.js`,
`packages${s}@okta${s}qtip2`
].some(filePathContains);
return shallBeExcluded && !npmRequiresTransform;
},
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
'./packages/@okta/babel-plugin-handlebars-inline-precompile',
'@babel/plugin-transform-modules-commonjs'
]
}
},
{
test: /\.json$/,
loader: 'json-loader'
},
// load external source maps
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre'
}
]
},
// Webpack attempts to add a polyfill for process
// and setImmediate, because q uses process to see
// if it's in a Node.js environment
node: {
process: false,
setImmediate: false
}
};
};