【发布时间】:2017-05-01 02:33:24
【问题描述】:
我正在尝试使用构建工具 brunch 为我的 react 应用程序制作一些样板。启动很容易,但我需要一些小东西来使我的开发更加完整。其中之一是环境变量。
我尝试了一些想法,但没有任何效果。诸如使用entryPoints 加载执行功能的配置 JS 文件之类的事情:
brunch-config.js
exports.files = {
javascripts: {
joinTo: {
'dependencies.js': /^(?!app\/)/,
'bundle.js': /^app\//
},
entryPoints: {
'app/confs.js': 'bundle.js'
}
},
stylesheets: {
joinTo: 'app.css'
},
};
exports.plugins = {
babel: { presets: ['latest', 'react'] }
};
confs.js
require('dotenv').config();
require('whatwg-fetch');
但是现在,什么都行不通...有人能给我一些想法吗?
提前致谢。
编辑
我在配置和结构中改变了一些东西,思路还是一样,在应用引导中加载polifylls和env变量。
现在confs.js 是init.js,并没有编译成bundle.js,而是在它自己的文件中编译成public/。
里面的代码是一样的,brunch-config.js是:
exports.files = {
javascripts: {
joinTo: {
'dependencies.js': /^(?!app\/)/,
'bundle.js': 'app/**/*[!init].js', // all but not init.js
'init.js': 'app/init.js' // put init.js in it's own file into public/
}
},
stylesheets: {
joinTo: 'app.css'
},
};
exports.plugins = {
babel: { presets: ['latest', 'react'] },
sass: {
options: {
includePaths: ['node_modules/normalize-css/']
}
}
};
但是编译后的init.js 在他的require.register() 中是空的,无论我在文件中放入什么代码:
require.register("init.js", function(exports, require, module) {
"use strict";
});
【问题讨论】:
标签: javascript brunch