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

Updating WebPack to version 3 #9

Closed
TAnas0 opened this issue Aug 17, 2017 · 4 comments
Closed

Updating WebPack to version 3 #9

TAnas0 opened this issue Aug 17, 2017 · 4 comments

Comments

@TAnas0
Copy link

TAnas0 commented Aug 17, 2017

Hi there,
I really like the concept behind your boilerplate of separating the frontend from the backend.
I am trying to update the whole boilerplate starting from WebPack.
The version included in your boilerplate is WebPack 1 if I am not mistaken.
I tried upgrading it to version 3. Apparently I only need to upgrade it to the version 2 since upgrading to version 3 is smooth and done through the command line via updating WebPack only.
I followed mainly the official guide and some other separate ressources of course to try to modify the "webpack.config.js" file.
I ended up with the following "webpack.config.js" file:

var sGrid = require('s-grid');
var rupture = require('rupture');
var autoprefixer = require('autoprefixer');
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './app/App.js'
  ],
  output: {
    pathinfo: true,
    path: path.resolve(__dirname, 'public'),
    filename: 'bundle.js',
    publicPath: 'http://localhost:3000/'
  },
  plugins: [
    new webpack.LoaderOptionsPlugin({
     options: {
       //postcss: [autoprefixer],
       context: __dirname,
       minimize: true
       //stylus: [sGrid, rupture]
     }
    }),
    new HtmlWebpackPlugin({
      title: 'React with Webpack and Redux - Meteor as a backend only!',
      template: './index_template.ejs',
      inject: 'body'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true, //in WebPack 2 it defaults to false so need to be explicitly set.
      compress: {
        warnings: true
      }
    })
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: ['babel-loader'] //'use' and 'loaders' are interchangeable
      },
      {
        test: /\.css$/, //scss??
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
              importLoaders: 2,
              localIdentName: '[name]__[local]__[hash:base64:5]',
              //plugins: autoprefixer,//WTF??
            }
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: function(){
                return [autoprefixer]
              }
            }
          }
        ]
        //loader: 'style!css?sourceMap&importLoaders=2&localIdentName=[name]__[local]__[hash:base64:5]!postcss'
      },
      {
        test: /\.styl$/,
        exclude: /(node_modules|bower_components)/,
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader',
            options:{
              sourceMap: true,
              modules: true,
              importLoaders: 2,
              localIdentName: '[name]__[local]__[hash:base64:5]'
              //plugins: sGrid, rupture
            }
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: function(){
                return [autoprefixer]
              }
            }
          },
          {
            loader: 'stylus-loader',
            options: {
              plugins: function(){
                return [sGrid, rupture]
              }
            }
          }
        ]
        //  loader: 'style!css?sourceMap&modules&importLoaders=2&localIdentName=[name]__[local]__[hash:base64:5]!postcss!stylus-loader'
      },
      {
        test: /\.(png|jpg)$/,
        exclude: /(node_modules|bower_components)/,
        use: [
          {
            loader: 'url-loader',
            options:{
              name: 'images/[name].[ext]',
              limit: '8192' //Maybe INT????
            }
          }
        ]
        //loader: 'url-loader?name=images/[name].[ext]&limit=8192'
      }
    ]
  },
  resolve: {
    //root: path.join(__dirname, '..', 'app'),
    modules: [
      path.join(__dirname, "app"), // 2 or 3 arguments??
      "node_modules"
    ],
    extensions: ['.js', '.jsx', '.json', '.css', '.styl', '.png', '.jpg', '.jpeg', '.gif'],
    enforceModuleExtension: false
  },
/*  stylus: function () {
    return [sGrid, rupture]
  },*/
/*  postcss: function () {
    return [autoprefixer];
  }*/
};

Still when I run npm start fron the client side I get the error in the picture attached, which is not really verbose. I can't pin the exact problem.

This is the debug file from npm.

2017-08-17T23_03_54_168Z-debug.txt
gitissue

I would highly appreciate your help on this, and I apologize i this is not the right place for this question.

@juliancwirko
Copy link
Owner

Hi, sorry I don't maintain this package anymore :/ I'll provide some information in the readme file.
Anyway, you can compare the config file with this one: https://github.com/juliancwirko/react-boilerplate/blob/master/webpack.config.js (I'll update this to Webpack 3 soon).

I think for Webpack 3 you would need to provide separate configuration file for PostCSS (https://github.com/postcss/postcss#webpack) or is it in Webpack 2? I am not sure. In Webpack 2 I've used options for PostCSS right in the webpack config file. Maybe both will work.

@juliancwirko
Copy link
Owner

...you can also integrate create-react-app ;) Which is complete and well documented. My starters were created before it existed.

@TAnas0
Copy link
Author

TAnas0 commented Aug 17, 2017

I'll go right into it, test it and be back.
Quick responses by the way, thank you

@juliancwirko
Copy link
Owner

@TAnas0 TAnas0 closed this as completed Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants