我在react中由于要使用jQuery的插件,因此使用npm install jquery --save的方式,在模塊中引入了jquery,在開發(fā)環(huán)境中使用是沒有問(wèn)題的。但是現(xiàn)在npm run build后,打開打包后的index.html文件,頁(yè)面會(huì)報(bào):jQuery is not defind的錯(cuò)誤。請(qǐng)教各位,這可能是什么原因呢?1.
1.webpack中也已經(jīng)定義好了jquery的全局變量。
2.webpack版本為1.x
webpack代碼:
//開發(fā)環(huán)境配置
var path = require('path')
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var OpenBrowserPlugin = require('open-browser-webpack-plugin');
// var nodeModulesPath = path.resolve(__dirname, 'node_modules')
// console.log(process.env.NODE_ENV)
module.exports = {
entry: path.resolve(__dirname, 'app/index.jsx'),
output: {
path: __dirname + "/build",
filename: "bundle.js"
},
resolve:{
extensions:['', '.js','.jsx'],
alias: {
handsontable: path.resolve(__dirname, 'node_modules/handsontable-pro')
}
},
module: {
// preLoaders: [
// // 報(bào)錯(cuò) ?????
// {test: /\.(js|jsx)$/, loader: "eslint-loader", exclude: /node_modules/}
// ],
loaders: [
{ test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader',
query: {
presets: ['react', 'es2015'],
//下面是使用 ant-design 的配置文件
plugins: ['react-html-attrs',["import", { "libraryName": "antd" }]]
}},
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css!postcss!less' },
{ test: /\.css$/, loader: 'style!css!postcss' },
{ test:/\.(png|gif|jpg|jpeg|bmp)$/i, loader:'url-loader?limit=5000&name=img/[name].[ext]' },
{ test:/\.(woff|woff2|svg|ttf|eot)($|\?)/i, loader:'url-loader?limit=5000&name=fonts/[name].[ext]'}
]
},
eslint: {
configFile: '.eslintrc' // Rules for eslint
},
postcss: [
require('autoprefixer') //調(diào)用autoprefixer插件,例如 display: flex
],
plugins: [
// html 模板插件
new HtmlWebpackPlugin({
template: __dirname + '/app/index.tmpl.html',
favicon: './ico/favicon.ico'
}),
// 熱加載插件
new webpack.HotModuleReplacementPlugin(),
// 打開瀏覽器
new OpenBrowserPlugin({
url: 'http://localhost:8090/#/login'
}),
// 可在業(yè)務(wù) js 代碼中使用 __DEV__ 判斷是否是dev模式(dev模式下可以提示錯(cuò)誤、測(cè)試報(bào)告等, production模式不提示)
new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse((process.env.NODE_ENV == 'dev') || 'false'))
}),
// 定義jQuery全局變量
new webpack.ProvidePlugin({
$:"jquery",
jQuery:"jquery",
"window.jQuery":"jquery"
}),
],
devServer: {
proxy: {
// 凡是 `/WHP.HydroPower` 或者 `/WHP.SSO` 開頭的 http 請(qǐng)求,都會(huì)被代理到 localhost:8080 上
'/WHP.HydroPower': {
target: 'http://localhost:8080',
secure: false
},
'/WHP.SSO': {
target: 'http://localhost:8080',
secure: false
}
},
contentBase: "./public", //本地服務(wù)器所加載的頁(yè)面所在的目錄
colors: true, //終端中輸出結(jié)果為彩色
historyApiFallback: true, //不跳轉(zhuǎn)
inline: true, //實(shí)時(shí)刷新
hot: true // 使用熱加載插件 HotModuleReplacementPlugin
}
}
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過(guò)二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。