Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for webpack #347

Closed
ericwooley opened this issue Jun 6, 2015 · 9 comments
Closed

support for webpack #347

ericwooley opened this issue Jun 6, 2015 · 9 comments

Comments

@ericwooley
Copy link
Contributor

@ericwooley ericwooley commented Jun 6, 2015

I can't get this going for the life of me in webpack. It keeps trying to load in fs, and something called dgram. I had to resort to importing the prebuilt minified version, which is not ideal.

Here is my webpack config

var HtmlWebpackPlugin = require('html-webpack-plugin')
var autoprefixer      = require('autoprefixer-core');
var csswring          = require('csswring');
var webpack           = require('webpack');
var path              = require('path');
var fs                = require('fs');

var config = {
  target: 'web',
  entry: ['webpack/hot/dev-server', './src/scripts/app.js'],
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: '[name].[hash].js',
    publicPath: '/'
  },
  eslint: {
    reporter: require("eslint-friendly-formatter"),
    // reporter: require("eslint/lib/formatters/stylish")
  },
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel', 'eslint'],
      exclude: /node_modules/
    }, {
      test: /\.scss$/,
      loader: 'style!css!postcss!sass'
    }, {
      test: /\.woff$|\.ttf$|\.wav$|\.mp3$/,
      loader: 'file'
    }, {
      test: /\.jpe?g$|\.gif$|\.png$|\.svg$/,
      loaders: [
        'url?limit=8192&hash=sha512&digest=hex&name=[hash].[ext]',
        'image?bypassOnDebug&optimizationLevel=7&interlaced=false'
      ]
    }, {
      test: /\.json$/,
      loader: 'json'
    },
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/template_index.html'
    })
  ],
  postcss: [autoprefixer, csswring],
  devtool: 'eval',
  devtool: 'sourcemap'
};

module.exports = config;
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 6, 2015

I prefer browserify and don't have experience with webpack. That said, you should look into getting webpack to support the "browser" field in package.json. It's an ad-hoc standard.

WebTorrent uses this field to tell packaging tools to ignore or replace certain modules when packaging for the browser. Obviously fs, net (tcp) and dgram (udp) don't make sense in the browser. :)

Here's an issue discussing how to get webpack to behave correctly: webpack/webpack#151

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 28, 2015

As far as I can tell, this issue can be resolved by following the instructions to enable the "browser" field in webpack that are described here: webpack/webpack#151 (comment) so I'm going to close this issue.

If this is not the case, feel free to open a new issue or comment here and I'll re-open this issue.

@feross feross closed this Jun 28, 2015
@yousefamar

This comment has been minimized.

Copy link
Contributor

@yousefamar yousefamar commented Oct 5, 2015

@ericwooley Did you manage to make it work with webpack in the end?

@ericwooley

This comment has been minimized.

Copy link
Contributor Author

@ericwooley ericwooley commented Oct 6, 2015

@Paraknight I ended up importing the prebuilt version, which webpack can do fine, but it spits out a warning at you. Something along the lines of:

import Webtorrent from 'webtorrent/webtorrent.min'

@chovy

This comment has been minimized.

Copy link
Contributor

@chovy chovy commented Jan 9, 2017

client is undefined when I do:

import WebTorrent from 'webtorrent/webtorrent.min`
const client = new WebTorrent()

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 19, 2017

@chovy Can you see if window.WebTorrent is getting defined? Maybe when you import this way, the normal UMD code gets confused and thinks there's no module environment.

@mitra42

This comment has been minimized.

Copy link

@mitra42 mitra42 commented Mar 5, 2018

Has anyone got this to work?
The webpack/webpack#151 (comment) points at https://webpack.js.org/configuration/resolve/#resolve-mainfields but this suggests how to specify your main file for a browser, BUT not how to use that to get webtorrent to not load fs.

For libsodium the fix was to add "browser": { "fs": false }, into package.json, but that doesnt work for webtorrent and the documentation linked to above is unclear to me whether there is a fix needed to webtorrent, or to the webpack config or somewhere else. and what that fix is.

@Chocobozzz

This comment has been minimized.

Copy link
Contributor

@Chocobozzz Chocobozzz commented Mar 5, 2018

@mitra42

This comment has been minimized.

Copy link

@mitra42 mitra42 commented Mar 5, 2018

Thanks - looks like that did it, I was following some other docs which suggested you wanted.

browser: { "fs": false } 

in the module itself.

I was interpreting "node" to mean compile for node, not fake something to look like node :-)

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.