Javascript 网页包模块源代码
我需要保存es6代码模块的代码并将其转储。 理想情况下,我需要的是:Javascript 网页包模块源代码,javascript,ecmascript-6,webpack,Javascript,Ecmascript 6,Webpack,我需要保存es6代码模块的代码并将其转储。 理想情况下,我需要的是: import React, {PropTypes} from 'react'; // this function get the source code of the // module I am running in function getMyModuleSourceCode = { ... } class DemoComponent extends React.Component { render() {
import React, {PropTypes} from 'react';
// this function get the source code of the
// module I am running in
function getMyModuleSourceCode = {
...
}
class DemoComponent extends React.Component {
render() {
const myCode = getMyModuleSourceCode();
processMySourceCode(myCode);
}
}
如果模块位于不同的文件中,则可以导入两次,一次是正常运行代码,一次是使用命令逐字输入文件
import module from './module'; //compiled code
import moduleSource from '!!raw!./module'; //source as text
如果您只是测试.js
扩展名,则需要使用code>来覆盖现有加载程序。如果模块位于不同的文件中,则可以导入两次,一次是正常运行代码,一次是使用命令逐字拉入文件
import module from './module'; //compiled code
import moduleSource from '!!raw!./module'; //source as text
如果您只是测试.js
扩展名,则必须使用code>来覆盖现有加载程序。您可以在网页包中使用,然后在函数中需要任何文件:
import React, {PropTypes} from 'react';
// this function get the source code of the
// module I am running in
function getMyModuleSourceCode = {
return require('!!file!./path/to/module.js');
}
class DemoComponent extends React.Component {
render() {
const myCode = getMyModuleSourceCode();
processMySourceCode(myCode);
}
}
您可以在Web包中使用,然后在函数中需要任何文件:
import React, {PropTypes} from 'react';
// this function get the source code of the
// module I am running in
function getMyModuleSourceCode = {
return require('!!file!./path/to/module.js');
}
class DemoComponent extends React.Component {
render() {
const myCode = getMyModuleSourceCode();
processMySourceCode(myCode);
}
}
我不能完全确定你的问题是什么,你能更准确一点吗?您希望在哪一点保存ES6模块的代码?网页是如何在这里发挥作用的?我更新了文本。我的猜测是,只有通过使用webpack,render函数中才可能知道模块的代码。因此,您希望在DemoComponent中包含另一个模块的源代码(而不是已编译的javascript)?我想要当前模块的源代码(而不是已编译的javascript)所以在DemoComponent中,我可以在控制台上的视频转储上进行统计/显示/无论什么。我不完全确定你的问题是什么,你能更精确一点吗?您希望在哪一点保存ES6模块的代码?网页是如何在这里发挥作用的?我更新了文本。我的猜测是,只有通过使用webpack,render函数中才可能知道模块的代码。因此,您希望在DemoComponent中包含另一个模块的源代码(而不是已编译的javascript)?我想要当前模块的源代码(而不是已编译的javascript)因此,在DemoComponent中,我可以在console/whatever.Wao上的视频转储上进行统计/显示