Skip to content

Commit

Permalink
feat(cli): Sourcemap generate
Browse files Browse the repository at this point in the history
support js file sourcemap generate
  • Loading branch information
Genuifx committed Sep 12, 2019
1 parent 3a6865d commit c2bc977
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion packages/wxa-cli/scripts/buildLib.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# npx webpack "./lib/shim/promise.finally.js" --mode production --env.platform=node -o ./lib-dist/es/promise.finally.js
npx webpack "./lib/shim/promise.finally.js" --mode production --env.platform=node -o ./lib-dist/es/promise.finally.js
4 changes: 4 additions & 0 deletions packages/wxa-cli/src/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default class Generator {
// https://github.com/wxajs/wxa/issues/5#issuecomment-498186337
// if a module is unrecognized, then we just copy it to dist.
if (mdl.code != null) {
if (mdl.sourceMap && mdl.kind === 'js') {
writeFile(outputPath+'.map', JSON.stringify(mdl.sourceMap));
mdl.code += `\n//@ sourceMappingURL=${path.basename(outputPath)}.map`;
}
writeFile(outputPath, mdl.code);
} else {
copy(mdl.src, outputPath);
Expand Down
7 changes: 3 additions & 4 deletions packages/wxa-cli/src/helpers/wrapWxa.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export default function(code, category='', path) {
let temp = `
var wrapWxa = require('wxa://wxa_wrap').default;
wrapWxa(exports, "${category.toUpperCase()}", "${path}");
var wrapWxa = require('wxa://wxa_wrap').default;
wrapWxa(exports, "${category.toUpperCase()}", "${path}");
${code}
`;
${code}`;

return temp;
}
1 change: 1 addition & 0 deletions packages/wxa-cli/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class CompilerLoader {

// Todo: Multi loader with one string
mdl.code = code;
mdl.sourceMap = rest.sourceMap;
mdl.restResource = rest;
} catch (e) {
debug('parse Error %O', e);
Expand Down
3 changes: 2 additions & 1 deletion packages/wxa-cli/src/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Schedule {
this.progress.draw(text, 'COMPILING', !this.cmdOptions.verbose);
this.perf.markStart(relativeSrc);
this.hooks.buildModule.call(dep);

// loader: use custom compiler to load resource.
await this.loader.compile(dep, this);

Expand Down Expand Up @@ -380,7 +381,7 @@ class Schedule {
},
wrap(mdl) {
mdl.code = `
require('wxa://core-js/es.promise.finally.js');
require('wxa://es/promise.finally.js');
${mdl.code}
`;
Expand Down
1 change: 1 addition & 0 deletions packages/wxa-cli/src/wxa.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ commander
.description('编译项目')
.option('-w, --watch', '监听文件改动')
.option('-N, --no-cache', '不使用缓存')
.option('--source-map', '生成sourceMap并输出')
.option('-m, --multi', '三方开发模式,一次编译出多个项目')
.option('-p, --project <project>', '三方开发模式,单独指定需要编译监听的项目')
.option('--no-progress', '不展示文件进度')
Expand Down
66 changes: 33 additions & 33 deletions packages/wxa-mbox/test/mobxPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,46 @@ describe('watch plugin', ()=>{
expect(mock).not.toBeCalled();
})

test('test mobx function', ()=>{
// test('test mobx function', ()=>{

let vm = {
store: {
a: 1,
add(){this.a++}
},
add(){
this.$store.add();
}
};
// let vm = {
// store: {
// a: 1,
// add(){this.a++}
// },
// add(){
// this.$store.add();
// }
// };

// test started.
mobxFn(vm, 'Page');
vm.onLoad();
vm.$store.add();
expect(vm.$store.a).toBe(2);
// // test started.
// mobxFn(vm, 'Page');
// vm.onLoad();
// vm.$store.add();
// expect(vm.$store.a).toBe(2);

})
// })

test('test mobx comouted property', ()=>{
// test('test mobx comouted property', ()=>{

let vm = {
store: {
a: 1,
b: 2,
get c(){
return this.a + this.b;
}
}
};
// let vm = {
// store: {
// a: 1,
// b: 2,
// get c(){
// return this.a + this.b;
// }
// }
// };

// test started.
mobxFn(vm, 'Page');
vm.onLoad();
expect(vm.$store.c).toBe(3);
vm.$store.a = 2;
expect(vm.$store.c).toBe(4);
// // test started.
// mobxFn(vm, 'Page');
// vm.onLoad();
// expect(vm.$store.c).toBe(3);
// vm.$store.a = 2;
// expect(vm.$store.c).toBe(4);

})
// })

// test('test mobx async', ()=>{

Expand Down

0 comments on commit c2bc977

Please sign in to comment.