Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Helicity posted:

Yeah, I was agreeing with what you said - there's no reason to sacrifice sanity when the performance gains likely aren't there. JavaScript VMs are insanely good at optimizing. Also agree on Redux being the poo poo :tipshat:

Well then. Let's agree to continue to agree, and I'll work on my reading comprehension in the new year.

:v:

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

kloa posted:

I really dislike the look of text-shadow, in an otherwise flat-design, but I can't really find a better way to display white text on a light background, such as yellow.

My conundrum is that the navigation tabs at the top are varying colors (not my choice). If I make the text black on yellow, then the black text on tabs that are dark are unreadable.

Amy tricks or ideas to have white text on both like and dark colored backgrounds?

Use a transparent not quite black shadow with 0 offsets and a big blur. Something like rgba(15, 15, 10, 0.5) 0px 0px 6px to start then play with the blur until it looks as least like crap as possible. Then hire a better designer for next time.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Click Beelay posted:

I hope this is the right place, looking for some insight.

I just graduated with a BSc in compsci and I've been offered a frontend position at a startup, which is owned by a huge company in my country, for pretty decent pay considering I have no real-world programming experience.

I'll be using JavaScript, React, Async, and Redux, and will apparently be given some exposure to backend (my preference) and mobile development.

:words:

My question - am I hosed, or is it likely that since I have no experience outside of uni I'm overthinking the difficulty of being thrown into several technologies I've never heard of? Finally, could anyone recommend some learning resources for the four things I've listed?

Thanks.

You are as far from hosed as you can be. Congrats on a job in what i think is a great environment to work on!

Here's a couple additional links I found informative useful to go along with sim's list (that egghead course is A++ stuff):

https://medium.com/front-end-developers/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4#.tt4ac93bv
http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html

(I am jealous as well!)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

caiman posted:

I'm beginning to hit a pain point with my React project and am wondering if Flux is the solution. I'm still pretty unfamiliar with Flux, so my question here is basically "is this what Flux is meant to solve?" My issue is with the ever growing complexity of passing props down a long chain of components. And then sometimes I have a method in a child that needs to be called from its parent, which I know can be done but isn't recommended. So I begin second guessing my choice of which component should hold a particular state, but moving it will alter the way I call it elsewhere... and my head starts to hurt.

Is Flux what I'm needing?

Seconding using Redux instead of a Flux implementation. I think there's a bunch of links to other resources (the key one being that egghead video in the first reply to you) posted in the last couple days in here or the JS thread.

Lumpy fucked around with this message at 19:00 on Feb 1, 2016

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Anony Mouse posted:

So, trying to wrap my head around React + Redux.

Take a look at this very, very basic example I put together: https://jsbin.com/xapeza/7/edit?js,output

Is this an acceptable design pattern? It seems sketchy to manually trigger forceUpdate() when one of the tenants of React is that components are supposed to just automatically respond to changes in state. I'm aware of react-redux, but I'm not quite sold on its purpose. Is it just to help connect Redux and React and avoid manually doing forceUpdate()? Does React's efficient diff engine mean that forceUpdate() isn't actually very costly?

Saying the same thing as the other guys: don't' use forceUpdate, but subscribe to the store and set props based on it. React-redux makes this super easy and watch the egghead videos as they will show you how it all works from a 'here's how we could do it... Refactor a bit to a better way, oh, and we can improve this here and look, you just wrote react-redux!"

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Came across this article today and thought it would be of interest: "Learn React without React" https://medium.com/@sharifsbeat/learn-the-concepts-part-1-418952d968cb#.kjirx7mxl

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

Bookmarking this one. I wish I had something like this when I was first starting out as I always learn faster and better when I've got this sort of overview information.


Also, I never got the stuff you were sending me. Maybe check into that for me?
Yeah, looking forward to the 2nd part.


As of the other thing: Whoops! On it...

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

Time for my once-every-few-months complaint about modern front-end development.

I put aside a project using modern front-end libraries for a a few months, did a few non-web-related projects, come back to it, have to spend a week or more upgrading all the libraries and fixing everything the upgrades broke.

Yeah, it's a lot my fault for using a bunch of modern, evolving stuff, but that was part of the point of this project.

I don't really blame the new, constantly-evolving projects for being constantly-evolving. I blame them for having terrible lovely changelogs and upgrade paths.

Prior the the past year or so I didn't spend a lot of time in the situation where I'd be setting projects aside like this. The experience has taught me that going forward I need to really evaluate how a library or framework does changelogs before adopting it.

Funnily enough, one of the non-web-related projects was a project I had also set aside for a few months...and on that one I had to upgrade just one library and it had no breaking changes.

Yep. Working with a startup and did the front-end in React / React-Router a few months ago, and it's working / all is well. After customer feedback and so on, time to make some changes! The other person on the project is going to do them, but got a new laptop.... nothing works. Oh, node is at 5.X and we were on 0.12.x... time to install nvm! Oh, we need to tweak some router stuff... look, the current docs look totally foreign!

:argh:

But like you said, it's the price you pay for choosing those tools.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

abraham linksys posted:

fwiw you can get away with using old versions of React/libs if you want, my main project is still on react-router 0.13.x and some old Flux implementation because it works fine

React itself has had little enough churn that it's not hard to use old libs with new versions for now, haven't had any major compatibility issues

Yeah, that's what we are doing (React 0.13, old router, old Alt, etc.) but it's just amazing that as a project that *started* six months ago, if you told someone to read up on React, Router, etc. today, they'd be seeing a whole different world in such a short time.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Feral Integral posted:

Aight I guess I don't really understand what people are really using angular for. In the past I've worked on django sites just rendering jinja templates to set the state of the page, but since this is supposed to be more of app, I'll need elements on the page to be dynamic without having to refresh the page. When this was necessary before, I'd just throw some javascript in the page to do ajax calls and update the page where it needed to be updated. I'm having trouble understanding how to replace this with something like angular, what advantages do I get?

PS: The more angular I get to use, the better - like you mentioned, it's used all over the place

Seconding starting with React over Angular if you have no explicit need to learn angular. React, as Thermo said is smaller, in that it's only the view, so you'll get more done faster, and when you are done, build it again in angular to see what's different and which you prefer. React coupled with Redux for state management is really easy to get your head around.

Lumpy fucked around with this message at 21:01 on Mar 6, 2016

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Time to play "What stupid and obvious thing is Lumpy missing" react-router version!!

JavaScript code:
//client.js
import routes from './routes';
const target = document.getElementById('root');
ReactDOM.render(
    <Provider store={ store }>
            <Router history={hashHistory} routes={routes} />
    </Provider>,
    target
);


//routes.js
import { App } from '../containers/App';
import LoginForm from '../components/LoginForm';

export default(
    <Route path='/' component={App}>
        <IndexRoute component={LoginForm}/>
    </Route>
);

//App.js
const App = React.createClass({
    render: function () {
        return (
            <div className="mainContentArea">
                <h1>Why isn't this rendered?</h1>
                <p>lolz</p>
                {this.props.children}
            </div> 
        );
    }
});
export default App;


//LoginForm.js
import React from 'react';
export default () => (
        <p>WTF</p>
);
So, I should see a "Why isn't this rendered" header, a "lolz" paragraph, then a "WTF" paragraph, right? I've used react-router many, many times, and this is what I expect. Instead, all I see is 'WTF'.

What stupid, stupid thing have I done?

EDIT: As always, when I read my post, I instantly saw the problem!

JavaScript code:
// inside routes.js .....

// original
import { App } from '../containers/App'; /// <-- Lumpy is dumb!

// changed to
import App from '../containers/App'; /// <-- All better
Thanks for listening to me debug.

Lumpy fucked around with this message at 17:16 on Mar 11, 2016

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Elm has been touched on earlier in this thread, and it was on my //TODO: list for a bit, and I had some time the other day to check it out, and it's pretty drat neat. Even though I don't think I'd use it for anything "real", it's a very, very good way of thinking functionally which has given my lots of "Ah ha!" moments for making React / Redux apps.

tl;dr: Elm:Two thumbs up!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Analytic Engine posted:

Thanks, sounds like a good tool for making complicated stuff that's reliabley "80% of the way there"

As for "is React Fast Enough" this article: http://swizec.com/blog/animating-with-react-redux-and-d3/swizec/6775 uses d3 for calculations and React to draw the SVGs and it seems pretty snappy. Might be something to look into as well.

As for "how to learn React", I'd read the Redux docs / watch the Redux egghead videos. Obviously very Redux specific, but those really get at the way React should work in my opinion.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
In other Modern Front End Development News™ I am almost done writing a standards compliant ES6 app with React + Redux..... and I haven't imported either of them yet. To me that's the biggest reason to use that combo. I have a fully unit-tested set of actions / action-creators / reducers that handle the UI, calls to remote services, etc. and have yet to use any "framework" code at all. The meat of the app is 100% portable in case I decide to use a different framework (or use additional frameworks like react-native.)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Kobayashi posted:

I have a very, very large project that uses LESS on the frontend. I'd like to integrate Zurb's Foundation Emails, which is written in SASS. Is there any non-idiotic way to integrate the two? Right now I'm considering some kind of awful two-phase compile process, where I have a small shim SASS file to override Foundation defaults and then the compiled CSS is imported to a LESS file, where all the project-specific classes are defined.

The other option I am considering is just going with SASS for the email component, and while that is good because it offloads the problem of figuring out how to support a million email clients onto Zurb, it creates a separation from the rest of the frontend, which will invariably mean the email styles will get out of sync with the rest of the project.

E: What I'd really like is to convert SASS to LESS. I see there's grunt-refactor but alas, the project uses Gulp.

modernFrontEnd.txt

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I know this gets asked semi-frequently, but since this is MODERN FRONT END, the answers change within seconds of Post being hit....

So: I am cranking away on a React SPA, and the last bit I have to flesh out is data storage. Right now I'm using localStorage, but I want users to be able to save in THE CLOUD because who doesn't love THE CLOUD, right? The data is effectively all JSON (it's actually all Immutable.js stuff, but thanks to .toJSON() we can ignore that for now) which means it's simple to send just about anywhere. First thought was just saving it in PostGRE and some sort of API I'd knock out w/ Django or something, but I'd like to both be lazy and try something new! So I am leaning towards using a service of some kind that allows me to store and retrieve JSON documents with user authentication and access control. I am looking at Firebase right now, and that seems like it will work, but might be a little overkill actually. What are you guys using this week?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Soooo.... Firebase it is!

Thanks for the input all! :tipshat:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Noam Chomsky posted:

Man Angular 2 really does seem to take simplish tasks and make you write super verbose complex code for them. I have been looking forward to Angular 2 but I keep seeing code that I have absolutely no interest in writing.

This is why React / Redux exists.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Noam Chomsky posted:

Thanks for these.

I think a lot of my problem is being stuck in Angular land after doing Angular 1.x for he last 2 years or enterprise clients. After mastering something so complex and developing some pretty good practices and structures for using the framework to great effect, it's tough to be told that now it's time to switch to something mostly totally new, and that goes for Angular 2 and React both.

My $0.02:

React is a pretty simple view framework. It also taught me about thinking the views of my web apps as simple state rendering machines. I can use React with whatever I decide to hand it state with, and I can use what I learned even if I dump React.

Redux is a pretty simple state management framework. It also taught me about immutability, functional programming concepts, and other neat stuff. I can use Redux no matter what I decide to render my views with, and I can use what I learned even if I dump Redux.

With Angular, I felt like I learned Angular, and when I ditched Angular, I "lost" everything.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Noam Chomsky posted:

It's weird that something that is dying keeps showing up in new courses, tutorials, and yeoman generators.

Welcome to front end development!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

dupersaurus posted:

Professional development question:

I sorta fell into web dev, but I'm sticking with it, and it's time to start moving on, but I know I have some holes. The site I inherited is php/mysql/jquery and I've since added angular 1&2 stuff. But the site was made by non-webdevs so it uses no frameworks, build tools, testing, etc. I've been burned before in interviews by that (why I picked up angular), so if I want to fill those gaps, what sorts of things would you guys recommend I look into?

React
Redux
SaSS
Webpack
ES6/2015
Django
Angular 2

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Chenghiz posted:

Yeah I consider the fact that react is almost completely vanilla JavaScript to be one of its major selling points, especially for a small team like mine.

:argh: BUT JSX!!! :argh:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

dupersaurus posted:

I've been using gulp and I'm starting to look into webpack, so I've got that step. The part I'm wondering about is how do you go from there to getting everything onto your production server. For example: my ward at work is an unholy mess of vanilla PHP and different flavors of JS, and pushing it is just checking in and merging into successive perforce branches until you get to live. So if I wanted to take the opportunity of an upcoming server rebuild to rethink how we do things, are there options out there?

For font-end SPA type stuff where the "deployment" is new JS / CSS bundles and an updated index.html with the new chunkhash(es) for said .js and .css files, I have a Makefile that has a bunch of rsync commands in it like so:


code:
rsync_upload: publish
rsync -e "ssh -p $(SSH_PORT)" --exclude-from '$(EXCLUDE_FILE)' -P -rvz 
      --delete $(PRODDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
Which runs webpack with it's production config, then puts things on the server.

Lumpy fucked around with this message at 17:01 on Jun 21, 2016

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Didn't we already have the broughaha over this a few months ago?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

The Merkinman posted:

Wow, no action for over a week on this thread?

I've asked before about Gulp, Grunt, etc. If I were to start using them (I still don't know why I would) do I need to make a new site entirely from scratch or could a web site be slowly updated, page by page, to use it?

Skip them and use webpack or plain npm scripts :v:

They *why* is because you want to perform build step from the time you hit 'save' to the time code gets to the browser. For example, when I save a file, webpack:

  • looks at the entry point of my code and gathers up all the imports for me into just what's used
  • transforms my ES6 to "vanilla" js
  • transforms my SASS into css
  • pulls out just the CSS that's actually used
  • autoprefixes that css
  • separates out all my "vendor" code (React, d3, whatever) into a separate file so it can be cached (in production)
  • minifies everything.
  • writes a new index.html for me with all the SCRIPT and LINK tags for the js /css
  • hot reloads my browser (in dev)

Plus probably a bunch of other stuff I forget.

If you write "raw" JS and CSS, then you don't really need that stuff.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

The Merkinman posted:

Thank you so much for that list.
Our JS is pretty raw, utilizing a lot of jQuery... though we just started using Angular 2.0 (typescript, requirejs) for part of our site.
I already have SCSS to CSS through some compass command thing that I don't even remember how I set up.

So, in general
Is all of this only really useful in DEV, and production wouldn't matter, or it's beneficial there too?
Would I need to start a whole new site-wide rebuild of the entire site to utilize this or could I update as I go (which I was able to do with the SCSS -> app.css workflow)

It's useful in both dev and production. I have a webpack config for dev (with hot reloading, source maps, etc.) and one for production (file splitting, extracting CSS to files, minify, etc.)

If you are using Angular 2, you'll need a transpiling step (typescript -> plain JS) already so, you can use npm / webpack to do that for you along with your SASS stuff all in one go. You can use these build tools either as glorified script runners (do SASS, then .ts, then...) or use them to for fancy stuff like bundle splitting and so on, so you can easily start on the simple side then add more stuff as you want.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

Quick question on the best way to handle this:

I have a large data file full of cities, along with country info, lat/long, etc. It's some 210k lines of JSON.

19.2 megs to be precise. Is there a good way to load that into memory on a node service and search it? Or would I be better off dumping it into a database?

I was trying to avoid databases altogether for the sake of simplicity, but this is the ONE use-case in favor of it.

I am using hapi, so I will be able to cache lookup responses, but I'm not sure how much that will save me anyway, since I doubt my userbase is going to be significant enough for the caching to come into play.

Will also accept: some sort of FREE webservice I can use to do this. I am using openweather's api, and they prefer weather lookups by city Id, which is where the datafile came from. Problem is - on their free plan I am only allowed 60 requests per minute, so I'd rather not do one for the city lookup, then one for the weather itself.

Suggestions?


TIA.

sqlite or mongo

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I came across this and thought I'd share: I Peeked Into My Node_Modules Directory And You Won’t Believe What Happened Next

I'm not sure what is funnier, the article or the comments from people who think it's real..... :v:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

crazysim posted:

It appears that some of it has been made real though!

https://github.com/babel/babel/commit/f36d07d30334f86412a9d2771880cb566a82a9b6



And there's nothing you can do about it.

hahaha one of the comments on the commit:

quote:

You idiots! This is 186 lines long! If all of babel could fit on one line, this would be 186 times bigger than babel itself!! (Or 186% bigger!!)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

xpander posted:

I'm writing a web app comprised of a frontend with Ember, and a backend with Flask. Currently I have the Ember app in a subfolder of the main project directory. I am about to do the initial git commit, and I'm wondering if I'm better off moving the Ember app into its own project folder and git repo. Any suggestions or comments in this regard?

Yes, you should have the front and back end in totally separate repos. That's my opinion obviously, but since (hopefully) the two projects aren't coupled, there is no reason to have to pull down the entire backed to make a change to the front end. There are places that do "one giant repo for everything " but I forget the reasoning for that. Not that it was be, I just can't remember.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

M31 posted:

But for a lot of projects, the front and backend are incredibly coupled from a functional perspective, which is the main reason you want them in one repository (often changes will require work on both the front and back).

If that's the case, then sure. I was thinking of the "modern front end " style of the backend being only exposed as an API and isn't coupled in any way to the front. I guess if your API changes though....

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

Any webpack gurus around?

I am setting up a project in it, and it's my first time, and I don't understand some things. Google is only being semi-helpful at this point.

What I want:

- EVERYTHING moved to a /public folder on build
- js built into bundle.js
- scss/css built into site.css
- dev server reloading all changes automagically

What I got (aside from lovin')

- bundle.js created in /public (yay!)

The problems:

- dev server does in fact rebuild the bundle, and site.css and moves them to the apropos directory. But I see no changes in the browser. Even if I manually clear cache / reload. So for now, I run the dev server in one terminal and webpack in a different one. After running just a plain build with webpack, refreshing shows my changes. Annoying as poo poo, from a workflow perspective.

- my index.html is in my src folder, which contains public. I want the index.html to be moved to public on build. I think I am probably just missing the loader to do that.



So yeah - I'm pretty webpack stupid, since this is the first time I have actually configured it myself. Suggestions are welcomed.

Have two configs. One for dev / hot reload (since dev server serves from memory) and one for build / prod (since that will put files places)

Here's my dev config. It uses an index.html file in project root that just has a script tag for bundle.js and the root DIV. This is fine, since in dev all js and css are all mushed up together.

JavaScript code:
// webpack.config.js
const path    = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer')

const sassLoaders = [
    'style-loader',
    'css-loader',
    'postcss-loader',
    'sass-loader?includePaths[]=' + path.resolve(__dirname, './src')
]

module.exports = {
    entry:  [
        'webpack-dev-server/client?[url]http://127.0.0.1:8080/[/url]',
        'webpack/hot/only-dev-server',
        './src/client.js'
    ],
    output: {
        publicPath: "/",
        path:     __dirname,
        filename: 'bundle.js',
    },
    resolve: {
        modulesDirectories: ['node_modules', 'shared'],
        extensions:         ['', '.js', '.jsx']
    },
    module: {
        noParse: [/moment.js/],
        loaders: [
            {
            test:    /\.jsx?$/,
            exclude: /node_modules/,
            loaders: ['react-hot', 'babel']
        },
        {
            test: /\.scss$/,
            loaders: sassLoaders
        },
        { 
            test: /\.(png|jpg)$/,
            loader: 'file-loader?name=[path][hash].[ext]' 
        },

        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ],
    devtool: 'inline-source-map',
};

I use a devServer file to actually run my dev envionment (with node devServer.js):

JavaScript code:
// devServer.js

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
  publicPath: config.output.publicPath,
  hot: true,
  historyApiFallback: true,
}).listen(8080, 'localhost', function (err, result) {
  if (err) {
    console.log(err);
  }
  console.log('Listening at localhost:8080');
});
and my production one, which breaks out all my dependencies into a vendor.js file so users cache it since that rarely changes. SASS/ CSS is pulled out into a separate file, and I use HtmlWebPackPlugin to generate a new index.html with all the correct file names. All generated files go into a /dist directory.

JavaScript code:
// weboapck.production.js
const path    = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const pkg = require('./package.json');
const deps = Object.keys(pkg.dependencies);


const sassLoaders = [
    'css-loader',
    'postcss-loader',
    'sass-loader?includePaths[]=' + path.resolve(__dirname, './src')
]

module.exports = {
    entry: {
        bundle: './src/client.js',
        vendor: deps
    },
    resolve: {
        modulesDirectories: ['node_modules', 'shared'],
        extensions:         ['', '.js', '.jsx']
    },
    output: {
        path:       path.join(__dirname, 'dist'),
        filename:   '[name].[chunkhash].js',
        chunkFilename: '[chunkhash].js',
        publicPath: '/'
    },
    devtool: 'cheap-module-source-map',
    module: {
        loaders: [
            {
            test:    /\.jsx?$/,
            exclude: /node_modules/,
            loaders: ['babel']
        },
        { 
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract(
                'style-loader',
                sassLoaders
            ) 
        },
        { 
            test: /\.(png|jpg)$/,
            loader: 'file-loader?name=[path][hash].[ext]' 
        },
        ]
    },
    plugins: [
        new ExtractTextPlugin("style.css", {allChunks: false}),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor', 'manifest']
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),
        new HtmlWebpackPlugin({
            chunksSortMode: 'dependency',
            title: 'YOUR TITLE HERE',
            template: 'appTemplate.ejs', 
            inject: 'body' 
        }),
    ]
};
I run a production build with:
code:
NODE_ENV=production webpack -p --progress --colors  --config webpack.production.js
Also, read this: http://survivejs.com/webpack/introduction/

Lumpy fucked around with this message at 14:32 on Aug 15, 2016

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

:monocle:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

Hot drat thats sexy.

I just installed it and yes. Yes it is.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

So I have a similar setup mostly up and running after tweaking your configs to suit my setup. The sass-loader is throwing an error on an @import line:

pre:
Error in ./~/sass-loader!./src/app/scss/main/scss
Module build failed:
@import 'colors';
^
    Invalid CSS after "...load the styles": expected 1 selector or at-rule, was "var content = requi"
    in main.scss (line 1, column1)
I get that for every time I use @import 'colors';

I don't know where "...load the styles" is coming from, since it's not in my repo anywhere.

Edit: now that I look, that
pre:
var content = requi
line isn't mine either. Hmm. module error?

in my SASS files I import other sass files like so:

code:
@import 'sass/config/_vars';
@import 'sass/util/_typography';
The paths above have to be relative to the path you set in your SASS loader:

code:
sass-loader?includePaths[]=' + path.resolve(__dirname, './src')
is what mine looks like, and my project structure looks like so:

code:
/-
 |- src/
    |- sass/
      |- util/
      |- config/
      |- components/
    |- js/
    ...
So my sass includes start looking from 'src/' and so I need to add the path(s) from there.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
The worst thing about Modern Front End Development is if you are attempting to learn something, and you find a nice tutorial that makes sense to you, then you see it was written over a month ago (gasp) so you probably shouldn't bother with it.

Hopefully in the next six months or so, things will converge towards sanity, but yeah, right now it's a poo poo-show. Hopefully we'll all jump ship to Elm in the next year or so.... :v:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

Yeah Elm is cool and good.

I mean, good luck if you're wanting to work with other people, because no one knows it.

I guess this thread will have to start a company. The Ultimate Goon Project....

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

The Merkinman posted:

Wait, so I shouldn't use Webpack? God dammit I hate this field. By the time I've leaned enough by reading the barebones documentation on a github page and typed in a bunch of npm install in a terminal like a 1990s hacker, then another articles comes along and says don't use X (use Y!). What the gently caress is the point in bothering to learn any of these, especially in my case where I only work on one website?

You should still use Webpack.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Anony Mouse posted:

Never preemptively optimize unless you know you need to.

But then what would we do all day?

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

The Merkinman posted:

OK after the words of encouragement I did the tutorial for Webpack.
It bundles the CSS with the JS and then injects the CSS inline in the head? Isn't that bad and will prevent the CSS file from being cached? Won't that be really bad when I switch it to my minified app.css that has styles for everything on the site?

I'm guessing I'm missing something, but the tutorial ended there.

I posted my dev and production configs here on in the JS thread a couple days ago. In dev, you bundle everything into one blob because you are just hot reloading out of memory. In production, your CSS is pulled out into a file, your 3rd party JS is pulled into a file, and your app code is pulled into a third file. These are all named by their chunks hashes, so if an update doesn't add any new deps or change styles, those files stay the same and cached.

You can get more complicated and have different bundling with more splits / files, but I haven't built anything complex enough to need it.


  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply