-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config_cannon.js
More file actions
120 lines (112 loc) · 3.87 KB
/
rollup.config_cannon.js
File metadata and controls
120 lines (112 loc) · 3.87 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
//import { terser } from 'rollup-plugin-terser';
const path = require('path');
const fs = require('fs');
var matched = require('matched');
const production = !process.env.ROLLUP_WATCH;
var curPackFiles=null; //当前包的所有的文件
var mentry = 'multientry:entry-point';
function myMultiInput(){
var include = [];
var exclude = [];
function configure(config) {
if (typeof config === 'string') {
include = [config];
} else if (Array.isArray(config)) {
include = config;
} else {
include = config.include || [];
exclude = config.exclude || [];
if (config.exports === false) {
exporter = function exporter(path) {
return `import ${JSON.stringify(path)};`;
};
}
}
}
var exporter = function exporter(path) {
return `export * from ${JSON.stringify(path)};`;
};
return(
{
options(options){
//console.log('===', options.input)
configure(options.input);
options.input = mentry;
},
resolveId(id, importer) {//entry是个特殊字符串,rollup并不识别,所以假装这里解析一下
if (id === mentry) {
return mentry;
}
var importfile= path.resolve(path.dirname(importer),id);
var ext = path.extname(importfile);
if(ext!='.js' && ext!='.glsl' && ext!='.vs' && ext!='.ps' &&ext!='.fs'){
importfile+='.js';
}
//console.log('import ', importfile);
if( curPackFiles.indexOf(importfile)<0){
//其他包里的文件
console.log('other pack:', importfile, id ,importer);
return 'Laya';
}else{
return importfile;
}
},
load(id){
if (id === mentry) {
if (!include.length) {
return Promise.resolve('');
}
var patterns = include.concat(exclude.map(function (pattern) {
return '!' + pattern;
}));
return matched.promise(patterns, {realpath: true}).then(function (paths) {
curPackFiles = paths; // 记录一下所有的文件
console.log(paths);
fs.writeFileSync('d:/temp/pp.ts',paths.join('\n'));
return paths.map(exporter).join('\n');
});
}else{
//console.log('load ',id);
}
}
}
);
}
export default {
input: [
'./bin/js/collision/**/*.js',
'./bin/js/constraints/**/*.js',
'./bin/js/equations/**/*.js',
'./bin/js/material/**/*.js',
'./bin/js/math/**/*.js',
'./bin/js/objects/**/*.js',
'./bin/js/shapes/**/*.js',
'./bin/js/solver/**/*.js',
'./bin/js/utils/**/*.js',
'./bin/js/world/**/*.js',
'./bin/js/layawrap/ctrls/ArcBall.js',
'./bin/js/layawrap/ctrls/KeyInputAction.js',
'./bin/js/layawrap/ctrls/PositionAction.js',
'./bin/js/layawrap/ctrls/RotationAction.js'
],
treeshake: false,
output: {
file: './build/layacannon.js',
format: 'iife',
sourcemap: false,
globals:{'Laya':'Laya'},
name:'cannon',
//intro:'window.Laya=window.Laya||exports||{};\n',
//outro:layaexpreplace
outro:'exports.version="'+(new Date())+'";window.cannon=exports;'
//indent: false
},
external:['Laya'],
plugins: [
myMultiInput()
//testPlug(),
//resolve(), // tells Rollup how to find date-fns in node_modules
//commonjs(), // converts date-fns to ES modules
//production && terser() // minify, but only in production
]
};