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

@kanaabe => Replace Browserify with Webpack #1785

Merged
merged 25 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"presets": [
"es2015",
["env", {
"targets": {
"browsers": ["last 2 versions"]
}
}],
"react",
"stage-3"
],
"plugins": [
"babel-plugin-rewire",
"inline-react-svg",
"transform-runtime",
["module-resolver", {
Expand All @@ -16,10 +19,16 @@
"env": {
"development": {
"plugins": [
["styled-components", {
"ssr": true
["babel-plugin-styled-components", {
"ssr": true,
"displayName": true
}]
]
},
"test" : {
"plugins": [
"babel-plugin-rewire"
]
}
}
}
2 changes: 2 additions & 0 deletions .env.oss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# as then we'll have to change it, making it harder for others to learn from.
# As such, these keys do not come under the Artsy security bounty either.

WEBPACK_DEVTOOL=cheap-module-source-map

# Shared
API_REQUEST_TIMEOUT=10000
API_URL=https://stagingapi.artsy.net
Expand Down
5 changes: 4 additions & 1 deletion desktop/analytics/article_impressions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const $ = require('jquery')
const _ = require('underscore')

if (location.pathname.match('/article/') || location.pathname.match('/articles')) {
var trackedImpressions = []

Expand Down Expand Up @@ -123,7 +126,7 @@ if (location.pathname.match('/article/') || location.pathname.match('/articles')
id: 'article_callout:' + articleId + ':' + destinationPath
}
} else {
return

}
}).toArray()

Expand Down
1 change: 0 additions & 1 deletion desktop/apps/auction/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import configureStore from 'desktop/components/react/utils/configureStore'
import { rehydrateClient } from 'desktop/components/react/utils/renderReactLayout'

export default () => {
// Rehydrate data from Server
const bootstrapData = rehydrateClient(window.__BOOTSTRAP__)
const auctionModel = new Auction(bootstrapData.app.auction)
const auctionArticles = new Articles(bootstrapData.app.articles)
Expand Down
6 changes: 5 additions & 1 deletion desktop/apps/auction/components/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class DOM extends Component {

componentDidMount () {
const FastClick = require('fastclick')
FastClick(document.body)

// removes 300ms delay
if (FastClick.attach) {
FastClick.attach(document.body)
}

this.$ = require('jquery')
this.addEventListeners()
Expand Down
6 changes: 5 additions & 1 deletion desktop/apps/auctions2/components/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class DOM extends Component {

componentDidMount () {
const FastClick = require('fastclick')
FastClick(document.body)

// removes 300ms delay
if (FastClick.attach) {
FastClick.attach(document.body)
}

this.$ = require('jquery')
this.addEventListeners()
Expand Down
6 changes: 4 additions & 2 deletions desktop/apps/inquiry/client/routes/inquiry.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
_ = require 'underscore'
attachFastClick = -> require('fastclick') arguments...
{ ARTWORK } = require('sharify').data
User = require '../../../../models/user.coffee'
Artwork = require '../../../../models/artwork.coffee'
Expand All @@ -10,10 +9,13 @@ openErrorFlash = require '../../../../components/inquiry_questionnaire/error.cof
Logger = require '../../../../components/logger/index.coffee'
Trail = require '../../../../components/inquiry_questionnaire/trail.coffee'
analytics = require '../../../../components/inquiry_questionnaire/analytics.coffee'
FastClick = require 'fastclick'
{ steps, decisions, views } = require '../map.coffee'


module.exports = (id, bypass) ->
attachFastClick document.body
if FastClick.attach
FastClick.attach document.body

steps = [bypass] if bypass and _.contains(_.keys(views), bypass)

Expand Down
2 changes: 2 additions & 0 deletions desktop/apps/inquiry/stylesheets/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

.inquiry-page
margin (main-header-height + 20px) 0
+respond-mobile()
padding 20px

.iqm-alert
position absolute
Expand Down
2 changes: 1 addition & 1 deletion desktop/apps/inquiry/test/client/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe 'mobile inquiry flow initialization', ->
jQuery: benv.require 'jquery'
Backbone.$ = $
initializeInquiry = rewire '../../client/routes/inquiry'
initializeInquiry.__set__ 'attachFastClick', sinon.stub()
initializeInquiry.__set__ 'FastClick', sinon.stub()
@StateView = initializeInquiry.__get__ 'StateView'
@render = sinon.stub @StateView::, 'render', -> this
done()
Expand Down
7 changes: 7 additions & 0 deletions desktop/apps/webpack/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { App } from './components/App'

ReactDOM.render(
<App />, document.getElementById('react-root')
)
18 changes: 18 additions & 0 deletions desktop/apps/webpack/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { Component } from 'react'
import styled from 'styled-components'

const Container = styled.div`
background: black;
font-size: 40px;
color: white;
`

export class App extends Component {
render () {
return (
<Container>
hi!!!!! 10
</Container>
)
}
}
8 changes: 2 additions & 6 deletions desktop/components/main_layout/templates/scripts.jade
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,12 @@ script( type="text/javascript" ).
if sharify
!= sharify.script()

//- Add Google's jQuery
script( src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js" )

//- Stripe
if options.stripe
script( type="text/javascript", src="https://js.stripe.com/v2/" )

//- Common bundle generated from factor-bundle
if sd.NODE_ENV !== 'development'
script( src=asset("/assets/common.js") )
//- Common bundle
script( src=asset("/assets/common.js") )

//- Analytics & common asset package
if sd.BROWSER && sd.BROWSER.family != 'PhantomJS'
Expand Down
2 changes: 2 additions & 0 deletions desktop/components/recently_viewed_artworks/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#recently-viewed-artworks
background-color gray-lightest-color
+respond-mobile()
padding 17px
.rva-container
padding-bottom 50px
.rva-header
Expand Down
4 changes: 3 additions & 1 deletion desktop/components/simple_contact/stylesheets/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
text-align center
border-bottom 1px solid gray-lighter-color
padding 0 0 20px
margin 0 -30px
+respond-desktop()
margin 0 -30px

.scontact-errors
.scontact-description
.scontact-from
Expand Down
2 changes: 1 addition & 1 deletion desktop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ app.use(require('./apps/feature'))
// User profiles
app.use(require('./apps/user'))

// React Serverside Example
// Examples
app.use(require('./apps/react_example'))
4 changes: 4 additions & 0 deletions desktop/lib/global_client_setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ setupJquery = ->
require '../../node_modules/jquery-touch-events/src/jquery.mobile-events.min.js'
require('artsy-gemini-upload') $
require('jquery-fillwidth-lite')($, _, imagesLoaded)

imagesLoaded = require 'imagesloaded'
imagesLoaded.makeJQueryPlugin($)

# For drop down menus that appear on hover you may want that menu to close
# once you click it. For these cases do `$el.click -> $(@).hidehover()` and
# the menu will hide and then remove the `display` property so the default
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cache.setup(() => {
artsyXapp.init({ url: API_URL, id: CLIENT_ID, secret: CLIENT_SECRET }, () => {
// Start the server
if (module === require.main) {
app.listen(PORT, () => console.log(`Force listening on port ${PORT}`))
app.listen(PORT, () => console.log(`\n\n [Force] Booting on port ${PORT}... \n`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this to mention http://localhost:${PORT} then the URL will be command+clickable in macOS terminals ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, this is deliberate so that the "compile" and "launch" phases remain distinct and the user doesn't open a browser to broken page. Once webpack is finished it outputs a clickable link 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah kk 👍

}
})
})
1 change: 0 additions & 1 deletion lib/middleware/error_handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = (err, req, res, next) ->
'../../desktop/components/error_handler/index.jade'
)
isDevelopment = NODE_ENV is 'development'
console.log err if isDevelopment
code = 504 if req.timedout
code ||= err.status || 500
message = err.message || err.text || err.toString() if isDevelopment
Expand Down
24 changes: 3 additions & 21 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,16 @@ export default function (app) {

// Static assets
if (NODE_ENV === 'development') {
app.use(require('./webpack-dev-server'))

app.use(require('stylus').middleware({
src: path.resolve(__dirname, '../desktop'),
dest: path.resolve(__dirname, '../desktop/public')
}))
app.use(require('browserify-dev-middleware')({
src: path.resolve(__dirname, '../desktop'),
transforms: [
require('babelify'),
require('caching-coffeeify'),
require('jadeify')
],
insertGlobals: true,
debug: true
}))
app.use(require('stylus').middleware({
src: path.resolve(__dirname, '../mobile'),
dest: path.resolve(__dirname, '../mobile/public')
}))
app.use(require('browserify-dev-middleware')({
src: path.resolve(__dirname, '../mobile'),
transforms: [
require('babelify'),
require('caching-coffeeify'),
require('jadeify')
],
insertGlobals: true,
debug: true
}))
}
glob.sync(`${__dirname}/../{public,{desktop,mobile}/**/public}`)
.forEach((fld) => app.use(express.static(fld)))
Expand Down Expand Up @@ -221,7 +203,7 @@ export default function (app) {
})

mountAndReload(path.resolve('desktop'), {
additionalModules: [
watchModules: [
'@artsy/reaction-force'
]
})
Expand Down
36 changes: 36 additions & 0 deletions lib/webpack-dev-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import express from 'express'
import webpack from 'webpack'
import path from 'path'

const app = module.exports = express()
const config = require(path.join(process.cwd(), 'webpack.config'))
const compiler = webpack(config)

app.use(require('webpack-hot-middleware')(compiler, {
log: false
}))

app.use(require('webpack-dev-middleware')(compiler, {
quiet: true,
publicPath: config.output.publicPath,
serverSideRender: true,
stats: {
colors: true
}
}))

// Testbed for various configurations
app.get('/webpack', (req, res, next) => {
res.send(`
<html>
<head>
<title>Webpack Test</title>
</head>
<body>
<div id='react-root' />
<script src='/assets/common.js'></script>
<script src='/assets/webpack.js'></script>
</body>
</html>
`)
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'waypoints/lib/jquery.waypoints.js'
require '../../../../node_modules/waypoints/lib/jquery.waypoints.js'

{ CITY, PARTNERS } = require('sharify').data
bootstrap = require '../../../components/layout/bootstrap.coffee'
Partners = require '../../../collections/partners.coffee'
Expand Down
2 changes: 1 addition & 1 deletion mobile/assets/mobile_all.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# to get more complex in how we break up and load assets.
#

require 'jquery'
$ = require 'jquery'
sd = require('sharify').data

# TODO: Refactor to use Backbone router
Expand Down
3 changes: 2 additions & 1 deletion mobile/assets/mobile_articles.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'jquery'
$ = require 'jquery'
require('backbone').$ = $
sd = require('sharify').data
articleIndex = require '../apps/articles/client/articles.coffee'
sectionView = require '../apps/articles/client/section.coffee'
ArticleView = require '../components/article/client/view.coffee'
Expand Down
15 changes: 13 additions & 2 deletions mobile/components/layout/bootstrap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'jquery'
Backbone = require 'backbone'
Backbone.$ = $

_ = require 'underscore'
FastClick = require 'fastclick'
RavenClient = require 'raven-js'
Expand All @@ -16,8 +17,18 @@ Cookies = require 'cookies-js'
{ parse } = require 'url'
HeaderView = require './client/header_view.coffee'
doc = window.document
sharify = require('sharify')


module.exports = ->
try
jqueryFillwidthLite = require 'jquery-fillwidth-lite'
imagesLoaded = require 'imagesloaded'
imagesLoaded.makeJQueryPlugin($)
jqueryFillwidthLite($, _, imagesLoaded)
catch error
# Noop used for tests. No need to setup

# Add the Gravity XAPP or access token to all ajax requests
$.ajaxSettings.headers = {
"X-XAPP-TOKEN": sd.ARTSY_XAPP_TOKEN
Expand All @@ -30,9 +41,9 @@ module.exports = ->
Cookies.set 'inquiry-referrer', doc.referrer
Cookies.set 'inquiry-session-start', location.href


# removes 300ms delay
FastClick document.body
if FastClick.attach
FastClick.attach document.body

setupErrorReporting()
setupHeaderView()
Expand Down
8 changes: 2 additions & 6 deletions mobile/components/layout/templates/scaffold.jade
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ html( class=htmlClass )
if sharify
!= sharify.script()

//- Add Google's jQuery
script( src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" )

//- Common bundle generated from factor-bundle
if sd.NODE_ENV !== 'development'
script( src=asset("/assets/common.js") )
//- Common bundle
script( src=asset("/assets/common.js") )

//- Include asset package's javascript
script( src=asset('/assets/' + assetPackage + '.js') )
Expand Down
Loading