-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.skpm.config.js
49 lines (48 loc) · 1.49 KB
/
webpack.skpm.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
'use strict';
let fs = require('fs');
let path = require('path');
let process = require('process');
/**
* Function that mutates original webpack config.
* Supports asynchronous changes when promise is returned.
*
* @param {object} config - original webpack config.
* @param {boolean} isPluginCommand - wether the config is for a plugin command or an asset
**/
module.exports = function (config, isPluginCommand) {
/** you can change config here **/
if (!isPluginCommand) return;
let debug = !!process.env.DEBUG;
if (!debug) clearMapFilesForProduction('sketch-meaxure.sketchplugin/Contents');
config.mode = debug ? 'development' : 'production';
config.entry = {
mark: './src/index.ts',
};
config.module = {
rules: [{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}]
};
config.resolve = {
extensions: ['.tsx', '.ts', '.js']
}
// config.output = {
// path: path.resolve(__dirname, skpmConfig.main, 'Contents', 'Sketch'),
// filename: '[name]_bundle.js'
// }
}
function clearMapFilesForProduction(dir) {
fs.readdirSync(dir).forEach(file => {
let fullName = path.resolve(dir, file);
if (fs.statSync(fullName).isDirectory()) {
clearMapFilesForProduction(fullName);
return;
}
if (file.endsWith('.js.map')) {
console.log('remove js map file', file);
fs.unlinkSync(fullName);
}
})
}