* [loader] fix with config/data case
diff --git a/weex-loader/index.js b/weex-loader/index.js
index e7c0252..ba21e07 100644
--- a/weex-loader/index.js
+++ b/weex-loader/index.js
@@ -18,7 +18,7 @@
function parseScript(loader, params, source, config, data) {
if (!scripter) {
- return Promise.reject('please use a script parser. ex. weex-scripter');
+ return Promise.reject('please use a script parser. e.g. weex-scripter');
}
var target = scripter.fix(source);
@@ -38,7 +38,7 @@
if (params.resourceQuery.entry === true) {
target += '\n;__weex_bootstrap__("@weex-component/' + name + '", ' +
- String(config) + ', ' +
+ String(config) + ',' +
String(data) + ')';
}
@@ -56,7 +56,7 @@
function parseStyle(loader, params, source) {
return new Promise(function(resolve, reject) {
if (!styler) {
- return reject('please use a style parser. ex. weex-styler');
+ return reject('please use a style parser. e.g. weex-styler');
}
styler.parse(source, function(err, obj) {
@@ -85,7 +85,7 @@
function parseTemplate(loader, params, source, deps) {
return new Promise(function(resolve, reject) {
if (!templater) {
- return reject('please use a template parser. ex. weex-styler');
+ return reject('please use a template parser. e.g. weex-templater');
}
templater.parse(source, function(err, obj) {
@@ -184,13 +184,14 @@
}
if (results.config) {
- config = JSON.parse(results.config.content);
+ config = new Function('return ' + results.config.content.replace(/\n/g, ''))();
}
config.transformerVersion = transformerVersion;
- config = JSON.stringify(config);
+ config = JSON.stringify(config, null, ' ');
if (results.data) {
- data = results.data.content;
+ data = new Function('return ' + results.data.content.replace(/\n/g, ''))();
+ data = JSON.stringify(data, null, ' ');
}
return parseScript(loader, params, content, config, data);
diff --git a/weex-loader/test/actual/a.js b/weex-loader/test/actual/a.js
index 90ab242..2bae027 100644
--- a/weex-loader/test/actual/a.js
+++ b/weex-loader/test/actual/a.js
@@ -61,7 +61,7 @@
__weex_module__.exports.style = __webpack_require__(7);
__weex_module__.exports.template = __webpack_require__(8);
})
- ;__weex_bootstrap__("@weex-component/48c34d39ea9ced4ad5f95df361368f61", {"transformerVersion":"0.3.1"}, undefined)
+ ;__weex_bootstrap__("@weex-component/48c34d39ea9ced4ad5f95df361368f61", {"transformerVersion":"0.3.1"},undefined)
/***/ },
/* 1 */
diff --git a/weex-loader/test/actual/z.js b/weex-loader/test/actual/z.js
new file mode 100644
index 0000000..9e78aee
--- /dev/null
+++ b/weex-loader/test/actual/z.js
@@ -0,0 +1,69 @@
+/******/ (function(modules) { // webpackBootstrap
+/******/ // The module cache
+/******/ var installedModules = {};
+
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+
+/******/ // Check if module is in cache
+/******/ if(installedModules[moduleId])
+/******/ return installedModules[moduleId].exports;
+
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = installedModules[moduleId] = {
+/******/ exports: {},
+/******/ id: moduleId,
+/******/ loaded: false
+/******/ };
+
+/******/ // Execute the module function
+/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+
+/******/ // Flag the module as loaded
+/******/ module.loaded = true;
+
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+
+
+/******/ // expose the modules object (__webpack_modules__)
+/******/ __webpack_require__.m = modules;
+
+/******/ // expose the module cache
+/******/ __webpack_require__.c = installedModules;
+
+/******/ // __webpack_public_path__
+/******/ __webpack_require__.p = "";
+
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(0);
+/******/ })
+/************************************************************************/
+/******/ ([
+/* 0 */
+/***/ function(module, exports) {
+
+ ;__weex_define__("@weex-component/060e94206c8ea81edded49ff8b7ca324", [], function(__weex_require__, __weex_exports__, __weex_module__){
+
+ ;__weex_module__.exports.template={
+ "type": "div"
+ }
+ })
+ ;__weex_bootstrap__("@weex-component/060e94206c8ea81edded49ff8b7ca324", {
+ "downgrade": {
+ "ios": {
+ "appVersion": ">=13.0.0"
+ },
+ "android": {
+ "appVersion": "<=0.0.0"
+ }
+ },
+ "transformerVersion": "0.3.1"
+ },{
+ "a": 1,
+ "b": 2
+ })
+
+/***/ }
+/******/ ]);
\ No newline at end of file
diff --git a/weex-loader/test/expect/z.js b/weex-loader/test/expect/z.js
new file mode 100644
index 0000000..501df2e
--- /dev/null
+++ b/weex-loader/test/expect/z.js
@@ -0,0 +1,14 @@
+define('@weex-component/z', function (require, exports, module) {
+
+;
+
+;module.exports.style = {}
+
+;module.exports.template = {
+ "type": "div"
+}
+
+;})
+
+// require module
+bootstrap('@weex-component/z', {"downgrade":{"ios":{"appVersion":">=13.0.0"},"android":{"appVersion":"<=0.0.0"}},"transformerVersion":"0.3.0"}, {"a":1,"b":2})
\ No newline at end of file
diff --git a/weex-loader/test/expect/z.we b/weex-loader/test/expect/z.we
new file mode 100644
index 0000000..b5b35d9
--- /dev/null
+++ b/weex-loader/test/expect/z.we
@@ -0,0 +1,23 @@
+<template>
+ <div></div>
+</template>
+
+<script type="data">
+{
+ a: 1,
+ b: 2
+}
+</script>
+
+<script type="config">
+{
+ downgrade:{
+ ios: {
+ appVersion: '>=13.0.0'
+ },
+ android: {
+ appVersion: '<=0.0.0'
+ }
+ }
+}
+</script>
\ No newline at end of file
diff --git a/weex-loader/test/test.js b/weex-loader/test/test.js
index 861798a..e22726a 100644
--- a/weex-loader/test/test.js
+++ b/weex-loader/test/test.js
@@ -39,4 +39,23 @@
expect(actualJson).eql(expectJson);
});
+
+ it('with config & data case', function() {
+ var name = 'z.js';
+
+ var actualCodePath = path.resolve(__dirname, 'actual', name);
+ var actualCodeContent = fs.readFileSync(actualCodePath);
+
+ var expectCodePath = path.resolve(__dirname, 'expect', name);
+ var expectCodeContent = fs.readFileSync(expectCodePath);
+
+
+ var actualResult = createInstance('actual/' + name, actualCodeContent);
+ var actualJson = getRoot('actual/' + name);
+
+ var expectResult = createInstance('expect/' + name, expectCodeContent);
+ var expectJson = getRoot('expect/' + name);
+
+ expect(actualJson).eql(expectJson);
+ });
})
\ No newline at end of file
diff --git a/weex-loader/webpack.config.js b/weex-loader/webpack.config.js
index 9beae50..6cf76bf 100644
--- a/weex-loader/webpack.config.js
+++ b/weex-loader/webpack.config.js
@@ -10,10 +10,13 @@
loader.useTemplater(templater);
module.exports = {
- entry: './test/a.js?entry=true',
+ entry: {
+ a: './test/a.js?entry=true',
+ z: './test/expect/z.we?entry=true'
+ },
output: {
path: './test/actual',
- filename: 'a.js'
+ filename: '[name].js'
},
module: {
loaders: [