电子不允许加载本地资源

时间:2017-03-09 07:28:16

标签: reactjs electron mobx mobx-react

我希望将使用MobX框架的React应用程序转换为Electron。 我已成功使用React加载MobX,但是当我尝试用Electron包装它时,我有一个控制台错误消息not allowed to load local resource

我的包JSON:

{
  "name": "electron-stuff",
  "version": "1.0.0",
  "description": "",
  "main": "src/electron.js",
  "scripts": {
    "babel": "babel",
    "webpack": "webpack",
    "start": "electron . --allow-file-access-from-files"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "mobx": "^2.3.7",
    "mobx-react": "^3.5.1",
    "react": "^15.2.1",
    "react-dom": "^15.3.0"
  },
  "devDependencies": {
    "babel-core": "^6.17.0",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-class-properties": "^6.10.2",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "css-loader": "^0.23.1",
    "react-addons-test-utils": "^15.3.0",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  }
}

我的webpack.config.js

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/main.js",
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
      },
      { test: /\.css$/, loader: "style-loader!css-loader" },
    ]
  },
  output: {
    path: path.join(__dirname, "src"),
    filename: "main.min.js"
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

为什么电子说他不允许加载本地资源?电子不认为有权访问本地文件?我怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

似乎我不小心走错了路。 问题解决了。