我的webpack.config.js文件如下
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'./js/config.js',
'./js/app.js'
],
output: {
path: __dirname,
filename: './js/app.bundle.js',
libraryTarget: 'var',
library: 'ui'
}
};
我的config.js文件具有app.js正在使用的全局变量baseURL config.js文件
var hostname_ = window.location.hostname;
var port_ = window.location.port;
var baseURL = "http://" + hostname_ + ":"+ port_ + "/admin/";
module.exports = {
baseURL: baseURL
};
浏览器中的我收到错误
ReferenceError: baseURL is not defined
答案 0 :(得分:1)
在app.js中导入baseURL:
import baseURL from './config'
或:
var baseURL = require('./config')