-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.core.config.js
executable file
·110 lines (102 loc) · 3.29 KB
/
webpack.core.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
106
107
108
109
110
const pathTo = require('path');
const fs = require('fs-extra');
const webpack = require('webpack');
const entry = {};
const weexEntry = {};
const vueWebTemp = 'temp';
const hasPluginInstalled = fs.existsSync('./web/plugin.js');
var isWin = /^win/.test(process.platform);
function getEntryFileContent(entryPath, vueFilePath) {
const relativePath = pathTo.relative(pathTo.join(entryPath, '../'), vueFilePath);
let contents = '';
if (hasPluginInstalled) {
const plugindir = pathTo.resolve('./web/plugin.js');
contents = 'require(\'' + plugindir + '\') \n';
}
if (isWin) {
relativePath.replace(/\\/g, '\\\\');
}
contents += 'var App = require(\'' + relativePath + '\')\n';
contents += 'App.el = \'#root\'\n';
contents += 'new Vue(App)\n';
return contents;
}
var fileType = '';
function walk(dir) {
dir = dir || '.';
const directory = pathTo.join(__dirname, 'src', dir);
fs.readdirSync(directory)
.forEach((file) => {
const fullpath = pathTo.join(directory, file);
const stat = fs.statSync(fullpath);
const extname = pathTo.extname(fullpath);
if (stat.isFile() && extname === '.vue' || extname === '.we') {
if (!fileType) {
fileType = extname;
}
if (fileType && extname !== fileType) {
console.log('Error: This is not a good practice when you use ".we" and ".vue" togither!');
}
const name = pathTo.join(dir, pathTo.basename(file, extname));
if (extname === '.vue') {
const entryFile = pathTo.join(vueWebTemp, dir, pathTo.basename(file, extname) + '.js');
fs.outputFileSync(pathTo.join(entryFile), getEntryFileContent(entryFile, fullpath));
entry[name] = pathTo.join(__dirname, entryFile) + '?entry=true';
}
weexEntry[name] = fullpath + '?entry=true';
} else if (stat.isDirectory() && file !== 'build' && file !== 'include') {
const subdir = pathTo.join(dir, file);
walk(subdir);
}
});
}
walk();
const plugins = [
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
}),
new webpack.BannerPlugin({
banner: '// { "framework": ' + (fileType === '.vue' ? '"Vue"' : '"Weex"') + '} \n',
raw: true,
exclude: 'Vue'
})
];
const weexConfig = {
entry: weexEntry,
output: {
path: pathTo.join(__dirname, 'dist', 'native'),
filename: '[name].js',
},
module: {
rules: [{
test: /\.js$/,
use: [{
loader: 'babel-loader',
query: {
presets: ["es2015"]
}
}],
exclude: /node_modules/
},
{
test: /\.vue(\?[^?]+)?$/,
use: [{
loader: 'weex-loader'
}]
},
{
test: /\.we(\?[^?]+)?$/,
use: [{
loader: 'weex-loader'
}]
}
]
},
plugins: plugins,
};
module.exports = {
weexConfig: weexConfig
}