spmjs / spm

Brand new static package manager.
http://spmjs.io
Other
903 stars 180 forks source link

如何只打包特定目录下的所有js文件? #1420

Closed max-lai closed 8 years ago

max-lai commented 8 years ago

index.js文件

require('./css/main.css');

window.$ = window.jQuery = require('jquery');
require('bootstrap');

//根据页面地址加载对应的controller
var path = window.location.pathname;
var ctr = path.replace(/((?!=.)[A-Z])/g,"-$1").replace(/\/-/g,'/').toLowerCase();
ctr = './src/controller/'+ ctr.replace('/home/','').replace('/','-');
require(ctr);

执行 spm build 会打包当前工作目录下的所有文件:如何只打包./src下面的所有的js文件?

jaredleechn commented 8 years ago

require 无法分析变量,如果动态异步加载模块的需求参考 https://github.com/spmjs/examples/tree/spm-webpack/load-on-demand