webpack打包jsx成nw.js目标文件,为何无法正常执行?

仅愚
  • 484

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

不引入 reactreact-dom则一切正常,但显然项目已经用了react不可能移除,请问我应该怎么处理?

回复
阅读 3.5k
1 个回答

process改为global.process试试

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏