This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.skpm.config.js
69 lines (59 loc) · 1.63 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const webpack = require('webpack');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
/**
* Function that mutates original webpack config.
* Supports asynchronous changes when promise is returned.
*
* @param {object} config - original webpack config.
* @param {boolean} isPluginCommand - whether the config is for a plugin command or an asset
**/
module.exports = function (config) {
const isDev = process.env.NODE_ENV === 'development';
// 修改 skpm 复制到 build 目录的方法
config.module.rules[1].use.query = {
raw: true,
outputPath(url) {
return path.posix.join('..', 'Resources', url);
},
publicPath(url) {
return `"file://" + String(context.scriptPath).split(".sketchplugin/Contents/Sketch")[0] + ".sketchplugin/Contents/Resources/${url}"`;
},
};
config.module.rules.push({
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: isDev,
configFile: path.resolve(process.cwd(), 'tsconfig.json'),
reportFiles: ['**/*.ts'],
},
},
],
});
if (!config.resolve) {
config.resolve = {
extensions: [],
};
}
config.resolve.extensions = [...config.resolve.extensions, '.ts'];
// transformations for production (publish)
if (!isDev) {
config.mode = 'production';
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
})
);
config.optimization = {
minimizer: [
new TerserPlugin({
test: /\.j|ts($|\?)/i,
}),
],
};
}
};