Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

process改为global.process试试


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...