-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from kaola-fed/issue12
feat: support use .vue file as entry, closes #12
- Loading branch information
Showing
13 changed files
with
170 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,9 @@ export default { | |
font-size: 29px; | ||
} | ||
</style> | ||
|
||
<config> | ||
{ | ||
"a": 1 | ||
} | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/target/lib/frameworks/shared/utils/extractPageFromScriptSource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { babel } = require( '../../../utils/babel' ) | ||
const extractConfigPlugin = require( '../../../babel-plugins/extract-config' ) | ||
const entryComponentPlugin = require( '../../../babel-plugins/entry-component' ) | ||
const mpTypePlugin = require( '../../../babel-plugins/mptype' ) | ||
const resolveSource = require( '../../../utils/resolveSource' ) | ||
const hashify = require( '../../../utils/hashify' ) | ||
const removeExtension = require( '../../../utils/removeExtension' ) | ||
|
||
module.exports = function ( source, loaderContext ) { | ||
const entryHelper = loaderContext.megaloEntryHelper | ||
|
||
const resourcePath = removeExtension( loaderContext.resourcePath, '.js' ) | ||
|
||
if ( entryHelper.isEntry( resourcePath ) ) { | ||
const entryKey = entryHelper.getEntryKey( resourcePath ) | ||
|
||
return Promise.resolve( { | ||
file: entryKey, | ||
config: null, | ||
entryComponent: { | ||
name: hashify( resourcePath ), | ||
}, | ||
} ) | ||
} | ||
|
||
return Promise.resolve( null ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const toString = Object.prototype.toString | ||
|
||
module.exports = function ( source ) { | ||
const loaderContext = this | ||
|
||
const entryHelper = loaderContext.megaloEntryHelper | ||
|
||
if ( entryHelper.isEntry( loaderContext.resourcePath ) ) { | ||
const entryKey = entryHelper.getEntryKey( loaderContext.resourcePath ) | ||
|
||
let config | ||
try { | ||
config = JSON.parse( source ) | ||
if ( toString.call( config ) !== '[object Object]' ) { | ||
config = {} | ||
} | ||
} catch ( e ) { | ||
config = {} | ||
} | ||
|
||
loaderContext.megaloCacheToPages( { | ||
file: entryKey, | ||
config: config, | ||
} ) | ||
} | ||
|
||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const qs = require( 'querystring' ) | ||
|
||
module.exports = source => source | ||
|
||
module.exports.pitch = function ( remainingRequest ) { | ||
const loaderContext = this | ||
const query = qs.parse( loaderContext.resourceQuery.slice( 1 ) ) | ||
const entryHelper = loaderContext.megaloEntryHelper | ||
|
||
// handle *.[framework] as entry | ||
if ( entryHelper.isEntry( loaderContext.resourcePath ) ) { | ||
const entryKey = entryHelper.getEntryKey( loaderContext.resourcePath ) | ||
|
||
// only pitch in first time | ||
if ( typeof query.vue === 'undefined' ) { | ||
return ` | ||
import Component from ${ JSON.stringify( '-!' + remainingRequest ) }; | ||
import Vue from 'vue'; | ||
Component.mpType = "${ entryKey === 'app' ? 'app' : 'page' }"; | ||
const app = new Vue(Component); | ||
app.$mount(); | ||
` | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/target/lib/loaders/entry.js → packages/target/lib/loaders/js-entry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
const composePlatformConfig = require( '../../shared/utils/composePlatformConfig' ) | ||
|
||
module.exports = function ( { config } ) { | ||
module.exports = function ( { config = {} } ) { | ||
const _config = composePlatformConfig( config, 'wechat' ) | ||
return JSON.stringify( _config, 0, 2 ) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters