-
Notifications
You must be signed in to change notification settings - Fork 127
/
webpack.config.js
65 lines (57 loc) · 1.74 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
const path = require('path')
const webpack = require('webpack')
const babelLoader = require('@skpm/builder/lib/utils/babelLoader').default({})
const PRODUCTION = process.env.NODE_ENV !== 'development'
const OUTPUT_PATH = path.resolve(__dirname, './build')
const ENTRIES = [
{ entry: './Source/index.js', output: 'SketchAPI.js' },
{ entry: './Source/async/index.js', output: 'SketchAPI_async.js' },
{
entry: './Source/data-supplier/index.js',
output: 'SketchAPI_data-supplier.js',
},
{ entry: './Source/dom/index.js', output: 'SketchAPI_dom.js' },
{ entry: './Source/settings/index.js', output: 'SketchAPI_settings.js' },
{ entry: './Source/ui/index.js', output: 'SketchAPI_ui.js' },
]
const CORE_MODULES = Object.keys(
require('./core-modules/package.json').dependencies
).map((k) => k.replace('@skpm/', ''))
babelLoader.test = /\.(ts|js)$/
const config = {
mode: PRODUCTION ? 'production' : 'development',
resolve: { extensions: ['.js', '.json'] },
module: {
rules: [babelLoader],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(PRODUCTION ? 'production' : 'development'),
API_VERSION: JSON.stringify(process.env.npm_package_version),
},
}),
],
externals: [
(context, request, callback) => {
// core modules shipped in Sketch
if (CORE_MODULES.indexOf(request) !== -1) {
return callback(null, `commonjs ${request}`)
}
return callback()
},
],
}
module.exports = ENTRIES.map(({ entry, output }) => ({
...config,
...{
entry,
output: {
filename: output,
libraryTarget: 'commonjs2',
path: OUTPUT_PATH,
},
},
}))
module.exports.config = config
module.exports.CORE_MODULES = CORE_MODULES