Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cymen
Created November 23, 2015 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cymen/9aec78c717c352ea0dc2 to your computer and use it in GitHub Desktop.
Save cymen/9aec78c717c352ea0dc2 to your computer and use it in GitHub Desktop.
webpack config with css, etc.
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonLoaders = [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions')
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!less-loader')
}, {
test: /\.sass/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!sass-loader')
}, {
test: /\.scss/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!sass-loader')
},
{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: /node_modules/
}, {
test: /\.json$/,
loaders: ['json-loader']
}
];
var assetsPath = path.join(__dirname, '/dist');
var publicPath = '/app/webpack/dist/';
module.exports = {
name: 'browser',
entry: [
path.join(__dirname, '/node_modules/babel-core/polyfill.js'),
path.join(__dirname, '/src/MyApp.js')
],
output: {
path: assetsPath,
publicPath: publicPath,
filename: 'bundle.js'
},
module: {
loaders: commonLoaders.concat([{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
}, {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}, {
test: /\.gif/,
loader: 'url-loader?limit=10000&mimetype=image/gif'
}, {
test: /\.jpg/,
loader: 'url-loader?limit=10000&mimetype=image/jpg'
}, {
test: /\.png/,
loader: 'url-loader?limit=10000&mimetype=image/png'
}, {
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true
}
}])
},
plugins: [
new ExtractTextPlugin('bundle.css', {
allChunks: true
})
]
};
@cymen
Copy link
Author

cymen commented Nov 23, 2015

package.json looks like:

{
  "name": "my_project",
  "version": "1.0.0",
  "engines": {
    "node": "~0.10.0"
  },
  "engineStrict": true,
  "devDependencies": {
    "babel-loader": "^5.1.3",
    "css-loader": "^0.14.4",
    "eslint": "^0.22.1",
    "eslint-plugin-react": "^2.5.0",
    "file-loader": "^0.8.4",
    "jasmine-core": "^2.3.4",
    "karma": "^0.13.9",
    "karma-babel-preprocessor": "^5.2.1",
    "karma-chrome-launcher": "^0.2.0",
    "karma-coverage": "0.5.0",
    "karma-firefox-launcher": "^0.1.6",
    "karma-jasmine": "^0.3.6",
    "karma-osx-reporter": "^0.2.0",
    "karma-phantomjs-launcher": "^0.2.1",
    "karma-sourcemap-loader": "^0.3.5",
    "karma-webpack": "^1.7.0",
    "less": "^2.5.1",
    "less-loader": "^2.2.0",
    "node-sass": "^3.2.0",
    "phantomjs": "^1.9.18",
    "react-addons-test-utils": "^0.14.2",
    "sass-loader": "^2.0.0",
    "sinon": "^1.14.1",
    "style-loader": "^0.12.3",
    "url-loader": "^0.5.6",
    "webpack": "^1.10.5"
  },
  "dependencies": {
    "autoprefixer-loader": "^3.1.0",
    "babel-core": "^5.4.7",
    "bootstrap": "3.3.4",
    "browser-version": "^1.0.0",
    "classnames": "^2.1.2",
    "d3": "^3.5.6",
    "dedupe": "^1.0.1",
    "email-validator": "^1.0.3",
    "es6-promise": "^3.0.2",
    "events": "^1.0.2",
    "extract-text-webpack-plugin": "^0.8.1",
    "font-awesome": "^4.3.0",
    "html5-history-api": "^4.2.1",
    "immutable": "^3.7.3",
    "isomorphic-fetch": "^2.2.0",
    "jade": "^1.11.0",
    "js-cookie": "^2.0.1",
    "json-loader": "^0.5.3",
    "kd.tree": "^0.1.3",
    "merge": "^1.2.0",
    "moment": "^2.10.3",
    "numeral": "^1.5.3",
    "object-equal": "^1.0.0",
    "omit": "^1.0.1",
    "path-is-absolute": "^1.0.0",
    "pikaday": "^1.3.2",
    "qs": "^3.1.0",
    "react": "^0.14.2",
    "react-bootstrap": "^0.28.1",
    "react-document-title": "^2.0.0",
    "react-dom": "^0.14.2",
    "react-progress": "0.0.9",
    "react-redux": "^0.2.2",
    "react-router": "1.0.0-beta3",
    "react-scroll-lock": "^0.1.1",
    "react-select": "^0.4.9",
    "redux": "1.0.0-rc",
    "scrollbar-width": "^3.1.1",
    "segmentio-commonjs-client": "0.0.8",
    "superagent": "^1.2.0",
    "titlecase": "^1.0.2",
    "underscore": "^1.8.2",
    "underscore.string": "^3.0.3",
    "xhr": "^2.0.1"
  },
  "eslintConfig": {
    "env": {
      "browser": true,
      "node": true,
      "jasmine": true,
      "es6": true
    },
    "globals": {
      "_UglyAppGlobal_": true
    },
    "ecmaFeatures": {
      "arrowFunctions": true,
      "binaryLiterals": true,
      "blockBindings": true,
      "classes": true,
      "defaultParams": true,
      "destructuring": true,
      "forOf": true,
      "generators": true,
      "modules": true,
      "objectLiteralComputedProperties": true,
      "objectLiteralShorthandMethods": true,
      "objectLiteralShorthandProperties": true,
      "octalLiterals": true,
      "regexYFlag": true,
      "spread": true,
      "superInFunctions": true,
      "templateStrings": true,
      "unicodeCodePointEscapes": true,
      "jsx": true
    },
    "plugins": [
      "react"
    ],
    "rules": {
      "camelcase": [
        2,
        {
          "properties": "never"
        }
      ],
      "quotes": [
        1,
        "single",
        "avoid-escape"
      ],
      "eqeqeq": 0,
      "curly": [
        2,
        "multi-line"
      ],
      "no-underscore-dangle": 1,
      "react/display-name": 1,
      "react/jsx-boolean-value": 1,
      "react/jsx-quotes": 1,
      "react/jsx-no-undef": 1,
      "react/jsx-sort-props": 0,
      "react/jsx-sort-prop-types": 1,
      "react/jsx-uses-react": 1,
      "react/jsx-uses-vars": 1,
      "react/no-did-mount-set-state": 1,
      "react/no-did-update-set-state": 1,
      "react/no-multi-comp": 1,
      "react/no-unknown-property": 1,
      "react/prop-types": 0,
      "react/react-in-jsx-scope": 1,
      "react/self-closing-comp": 1,
      "react/wrap-multilines": 1,
      "space-infix-ops": 0,
      "new-cap": 0
    }
  },
  "scripts": {
    "lint": "./node_modules/eslint/bin/eslint.js src spec webpack.config.js karma.dev.conf.js karma.test.conf.js",
    "build-dev": "node ./node_modules/webpack/bin/webpack.js -d -w",
    "build-prod": "node ./node_modules/webpack/bin/webpack.js -p",
    "test": "npm run lint && ./node_modules/karma/bin/karma start karma.test.conf.js --single-run",
    "test-dev": "./node_modules/karma/bin/karma start karma.dev.conf.js",
    "watch": "node ./node_modules/webpack/bin/webpack.js -w --devtool eval"
  }
}

@cymen
Copy link
Author

cymen commented Nov 23, 2015

Note the package.json is off a branch that is WIP on doing some server-side rendering so it has some things in it temporarily like express.

@drewhamlett
Copy link

Thanks for taking the time to put this together! How are you exactly using this with Rails? Or is your front end separated out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment