webpack打包jsx成nw.js目标文件,为何无法正常执行?
webpack.config.js如下:
/**
* Created by shijinyu on 2017/3/3.
*/
const path = require("path")
const StringReplacePlugin = require('string-replace-webpack-plugin')
const utils = require('./utils')
var cwd = process.cwd()
var autoprefixer = require('autoprefixer')
module.exports = {
entry : ["index.jsx"]
output:{
path: path.resolve(cwd, "./static/"),
filename:"[name].js"
},
externals:{
// "jquery":"jQuery"
// "React":"React"
// "nw.gui" : "nw.gui"
},
resolve:{
extensions:['.js','.jsx','.scss'],
alias:{}
},
resolveLoader:{
modules : [path.join(__dirname,"src/libs"),"node_modules"]
},
plugins:[
new StringReplacePlugin()
],
module:
rules: [
{
test: /\.(js|jsx)$/,
use: [{
loader : StringReplacePlugin.replace({
replacements: getReplace(),
})
},{
loader:"eslint-loader"
},{
loader : "babel-loader",
}],
exclude: /node_modules|build/
}, {
test: /\.json$/,
use: 'json-loader'
}, {
test: /\.(scss|sass)$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader", // compiles Sass to CSS
options: {
// includePaths: ["absolute/path/a", "absolute/path/b"]
}
}]
},{
test:/\.html$/,
loader:"ejs2-loader"
}, {
test: /\.(png|jpg|gif|svg|woff|woff2|eot|ttf)$/,
loader: 'url-loader',
options: {
limit: 6000,
name: '[name].[ext]?[hash]'
}
}
]
}
},
target:"node-webkit"
}
index.jsx文件如下:
import "./index.scss";
import $ from "jquery";
import React from "react";
import {render} from "react-dom";
import Launch from "../../components/launch/launch";
render(
<Launch />,
document.getElementById("J_launch")
);
nw.js app的控制台中报错:
Uncaught ReferenceError: process is not defined
不引入 react
和react-dom
则一切正常,但显然项目已经用了react不可能移除,请问我应该怎么处理?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
process改为global.process试试