Repository navigation
Expand file tree
/
Copy pathmpb.config.js
More file actions
147 lines (145 loc) · 4.8 KB
/
Copy pathmpb.config.js
File metadata and controls
147 lines (145 loc) · 4.8 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Created by ximing on 2019-03-14.
*/
const path = require('path');
const MPB = require('mpbuild');
const TestPlugin = require('./plugins/testPlugin');
const minimize_path = !!process.env.minimize_path;
const dist = minimize_path ? 'minimize_path_dist' : 'dist';
const projectNames = [
path.join(__dirname, '../projects/one'),
path.join(__dirname, '../projects/two'),
];
module.exports = {
// 入口配置文件
entry: './entry.js',
// 源码对应目录
src: path.join(__dirname, 'src'),
alias: {
'@one': path.join(__dirname, '../projects/one'),
'@two': path.join(__dirname, '../projects/two'),
'@utils': path.join(__dirname, 'src/utils'),
'@root': path.join(__dirname, 'src'),
'@components': path.join(__dirname, 'src/components'),
'@/': function (asset, opt) {
const { filePath } = asset;
return projectNames.reduce((projectPath) => {
if (filePath.includes(projectPath)) return projectPath;
});
},
},
output: {
path: path.join(__dirname, dist),
npm: 'npm',
component: {
relative: true,
},
},
optimization: {
// 如果需要压缩,配置 JS 固话需要过滤的 comment
minimize: {
// js: needUglify ? { output: { comments: /javascript-obfuscator:disable|javascript-obfuscator:enable/} } : false,
js: false,
wxml: false,
json: false,
path: minimize_path,
pool: false,
},
},
module: {
rules: [
{
test: /\.wxss$/,
use: [
{
loader: 'postcss-loader',
options: {
parser: require('postcss-scss'),
plugins: [
require('@yeanzhi/postcss-advanced-variables')({
variables: {},
importResolve: async (id, cwd, opts) => {
const file = require('path').resolve(cwd, id);
if (file.includes('mixin')) {
return {
file,
contents: require('fs').readFileSync(file, 'UTF-8'),
};
}
},
importFilter: (id) => {
return id.includes('mixin');
},
}),
require('postcss-nested')({ bubble: ['keyframes'] }),
],
},
},
],
},
{
test: /\.js$/,
include: [],
exclude: ['**/node_modules/**'],
use: [
{
loader: 'babel-loader',
options: { comments: true },
},
],
},
{
test: /\.json$/,
use: [
{
loader: 'json-loader',
},
],
},
{
test: /\.wxs$/,
use: [],
},
{
test: /\.wxml$/,
use: [],
},
],
},
plugins: [
new MPB.PolymorphismPlugin({ platform: 'wx', blockcode: true }),
new MPB.CleanMbpPlugin({
path: [`${dist}/**/*`, `!${dist}/project.config.json`],
}),
// new MPB.TsTypeCheckPlugin({
// project: __dirname
// }),
new MPB.ProjectConfigPlugin({
projectname: 'test',
appId: 'test',
setting: {
minified: true,
},
}),
new MPB.SubProjectPlugin({
subProjects: [
{
name: '@one',
alias: {
'@two-b': path.join(__dirname, '../projects/two/utils/b.js'),
'@one': path.join(__dirname, '../projects/one'),
},
src: path.join(__dirname, '../projects/one'),
},
{
name: '@two',
alias: {
'@two': path.join(__dirname, '../projects/two'),
},
src: path.join(__dirname, '../projects/two'),
},
],
}),
new TestPlugin(),
],
};