├── .babelrc ├── .editorconfig ├── .gitignore ├── .npmignore ├── .sailsrc ├── .travis.yml ├── README.md ├── api └── hooks │ └── webpack │ └── index.js ├── config └── webpack.js ├── gulpfile.js ├── package.json └── test ├── bootstrap.test.js ├── hook.js └── mocha.opts /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ################################################ 3 | ############### .gitignore ################## 4 | ################################################ 5 | # 6 | # This file is only relevant if you are using git. 7 | # 8 | # Files which match the splat patterns below will 9 | # be ignored by git. This keeps random crap and 10 | # sensitive credentials from being uploaded to 11 | # your repository. It allows you to configure your 12 | # app for your machine without accidentally 13 | # committing settings which will smash the local 14 | # settings of other developers on your team. 15 | # 16 | # Some reasonable defaults are included below, 17 | # but, of course, you should modify/extend/prune 18 | # to fit your needs! 19 | ################################################ 20 | 21 | dist/ 22 | *.sw* 23 | 24 | ################################################ 25 | # Local Configuration 26 | # 27 | # Explicitly ignore files which contain: 28 | # 29 | # 1. Sensitive information you'd rather not push to 30 | # your git repository. 31 | # e.g., your personal API keys or passwords. 32 | # 33 | # 2. Environment-specific configuration 34 | # Basically, anything that would be annoying 35 | # to have to change every time you do a 36 | # `git pull` 37 | # e.g., your local development database, or 38 | # the S3 bucket you're using for file uploads 39 | # development. 40 | # 41 | ################################################ 42 | 43 | config/local.js 44 | 45 | 46 | 47 | 48 | 49 | ################################################ 50 | # Dependencies 51 | # 52 | # When releasing a production app, you may 53 | # consider including your node_modules and 54 | # bower_components directory in your git repo, 55 | # but during development, its best to exclude it, 56 | # since different developers may be working on 57 | # different kernels, where dependencies would 58 | # need to be recompiled anyway. 59 | # 60 | # More on that here about node_modules dir: 61 | # http://www.futurealoof.com/posts/nodemodules-in-git.html 62 | # (credit Mikeal Rogers, @mikeal) 63 | # 64 | # About bower_components dir, you can see this: 65 | # http://addyosmani.com/blog/checking-in-front-end-dependencies/ 66 | # (credit Addy Osmani, @addyosmani) 67 | # 68 | ################################################ 69 | 70 | node_modules 71 | bower_components 72 | 73 | 74 | 75 | 76 | ################################################ 77 | # Sails.js / Waterline / Grunt 78 | # 79 | # Files generated by Sails and Grunt, or related 80 | # tasks and adapters. 81 | ################################################ 82 | .tmp 83 | dump.rdb 84 | 85 | 86 | 87 | 88 | 89 | ################################################ 90 | # Node.js / NPM 91 | # 92 | # Common files generated by Node, NPM, and the 93 | # related ecosystem. 94 | ################################################ 95 | lib-cov 96 | *.seed 97 | *.log 98 | *.out 99 | *.pid 100 | npm-debug.log 101 | 102 | 103 | 104 | 105 | 106 | ################################################ 107 | # Miscellaneous 108 | # 109 | # Common files generated by text editors, 110 | # operating systems, file systems, etc. 111 | ################################################ 112 | 113 | *~ 114 | *# 115 | .DS_STORE 116 | .netbeans 117 | nbproject 118 | .idea 119 | .node_history 120 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langateam/sails-webpack/29814fb8d55b7ff7d711c3400f6ace8704c1113c/.npmignore -------------------------------------------------------------------------------- /.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "grunt": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.12' 4 | - '4.0' 5 | - '5.0' 6 | 7 | notifications: 8 | email: false 9 | 10 | deploy: 11 | provider: npm 12 | email: hello@balderdash.io 13 | api_key: 14 | secure: TJfI/+izMobmNGrJtq74VVTYu8HSqYR2onl83/NSRO2Ud6joJUckq58+VWDc3ILd+ZFjODdtR5nnrn0waE9fgaNO136F0J/W1BRYsyHQbedRnPLBA1cnUHD233KHGS1Sk5ayL5YhGpzR/ybJQ/dnUajgW2LcZhgu6UFWc61Wx0SV1gEsqAxl+H0e591u+Q8LvVNq/TT1ATr7kHSiff0bfGahc7WeEf9XCMmWLczFPz07kZyFLMPhP4WuvC1mtcC0ipqrxWa3bb60JN3NizTlEEe3qMh/v7UKSun2LzHUvCPq8lYU/VYUrkoXEVOuB+Lykw/FzbwpgKa/WrABVI5juk6jhvff2Acqv/19O0jLO9jpTFnwHN9t6QeCwUKw2M4xB7UTkwedFr1GMVAOLS/Xdv6t/5cgika0DP6pBWMejYOfwvkZM2RJtrvOQqBsJTfJGPTMr11iUUFeBQ8FpdfX2k0Q1PrJmgHFv1gZ2bgXgYf8dWHmVgNah6s8Xg+fp2vC5UOfeczqb3BGXBR5+eC67tMbZ9Ch1HK1nzmpqWGzRI+eCmMxzsgGPUvzKYc/LwWv4k8SfWOZ23iTDQ9xhAenx5rQzPpmgd2Zx4pUWcN29zY5A04l3UQBH0E1H55HcbbnC8PnyCQgEFoUNxVYxpGnaog15W37fmG1oQQ4Va8WAPo= 15 | on: 16 | tags: true 17 | repo: balderdash-projects/sails-webpack 18 | all_branches: true 19 | 20 | sudo: false 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sails-webpack 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![Build status][travis-image]][travis-url] 5 | [![Dependency Status][daviddm-image]][daviddm-url] 6 | 7 | Webpack asset pipeline hook for Sails. 8 | 9 | ## 1. Install 10 | ```sh 11 | $ npm install sails-webpack --save 12 | ``` 13 | 14 | ## 2. Configure 15 | 16 | ### a. Disable the built-in Grunt hook 17 | 18 | ```js 19 | // .sailsrc 20 | { 21 | "hooks": { 22 | "grunt": false 23 | } 24 | } 25 | ``` 26 | 27 | ### b. Set your environment. 28 | 29 | By default, Sails ([and express](http://stackoverflow.com/a/16979503/291180)) sets `NODE_ENV=development`. 30 | In this setting, webpack will watch for changes in the directories you specify in your `config/webpack.js`. 31 | 32 | 33 | | `NODE_ENV` | webpack mode | description | 34 | |:---|:---|:---| 35 | | `development` | [`webpack.watch()`](https://webpack.github.io/docs/configuration.html#watch) | Rebuilds on file changes during runtime | 36 | | `staging` or `production` | `webpack.run()` | Build bundle once on load. | 37 | 38 | ### c. Configure Webpack 39 | 40 | This hook uses standard [Webpack Configuration](https://webpack.github.io/docs/configuration.html). 41 | Below is an example of using webpack to compile a [React.js](https://facebook.github.io/react/) application located in `assets/js/`. 42 | 43 | ```js 44 | // config/webpack.js 45 | 46 | var webpack = require('webpack'); 47 | var path = require('path'); 48 | 49 | // compile js assets into a single bundle file 50 | module.exports.webpack = { 51 | options: { 52 | devtool: 'eval', 53 | entry: [ 54 | './assets/js', 55 | ], 56 | output: { 57 | path: path.resolve(__dirname, '../.tmp/public/js'), 58 | filename: 'bundle.js' 59 | }, 60 | plugins: [ 61 | new webpack.HotModuleReplacementPlugin(), 62 | new webpack.NoErrorsPlugin() 63 | ], 64 | module: { 65 | loaders: [ 66 | // requires "npm install --save-dev babel-loader" 67 | { test: /\.js$/, loaders: ['babel-loader?stage=0'] }, 68 | { test: /\.css$/, loader: 'style!css' } 69 | ] 70 | } 71 | }, 72 | 73 | // docs: https://webpack.github.io/docs/node.js-api.html#compiler 74 | watchOptions: { 75 | aggregateTimeout: 300 76 | } 77 | }; 78 | ``` 79 | 80 | ## 3. Update your Layout 81 | 82 | ```html 83 | 84 | 85 | ``` 86 | 87 | ## 4. Lift! 88 | 89 | ```sh 90 | $ sails lift 91 | ``` 92 | 93 | ## License 94 | MIT 95 | 96 | ## Maintained By 97 | [](http://langa.io) 98 | - [Joey Di Nardo](https://github.com/yejodido) 99 | - [Weyland Joyner](https://github.com/weyj4) 100 | - [Travis Webb](https://github.com/tjwebb) 101 | 102 | [npm-image]: https://img.shields.io/npm/v/sails-webpack.svg?style=flat-square 103 | [npm-url]: https://npmjs.org/package/sails-webpack 104 | [travis-image]: https://img.shields.io/travis/langateam/sails-webpack.svg?style=flat-square 105 | [travis-url]: https://travis-ci.org/langateam/sails-webpack 106 | [daviddm-image]: http://img.shields.io/david/langateam/sails-webpack.svg?style=flat-square 107 | [daviddm-url]: https://david-dm.org/langateam/sails-webpack 108 | -------------------------------------------------------------------------------- /api/hooks/webpack/index.js: -------------------------------------------------------------------------------- 1 | import Marlinspike from 'marlinspike' 2 | import webpack from 'webpack' 3 | import _ from 'lodash' 4 | 5 | class Webpack extends Marlinspike { 6 | constructor (sails) { 7 | super(sails, module) 8 | } 9 | 10 | configure () { 11 | let config = this.sails.config 12 | 13 | if (!config.webpack.options) { 14 | sails.log.warn('sails-webpack: no Webpack "options" are defined.') 15 | sails.log.warn('sails-webpack: Please configure config/webpack.js') 16 | } 17 | } 18 | 19 | initialize (next) { 20 | let config = this.sails.config 21 | next() 22 | 23 | sails.after('lifted', () => { 24 | this.compiler = webpack(_.extend({ }, this.sails.config.webpack.options), (err, stats) => { 25 | if (err) throw err; 26 | 27 | sails.log.info('sails-webpack: compiler loaded.') 28 | sails.log.silly('sails-webpack: ', stats.toString()) 29 | 30 | if (process.env.NODE_ENV == 'development') { 31 | sails.log.info('sails-webpack: watching...') 32 | this.compiler.watch(_.extend({ }, this.sails.config.webpack.watchOptions), this.afterBuild) 33 | } 34 | else { 35 | sails.log.info('sails-webpack: running...') 36 | this.compiler.run(this.afterBuild) 37 | } 38 | }) 39 | }) 40 | } 41 | 42 | afterBuild (err, rawStats) { 43 | if (err) return sails.log.error('sails-webpack: FATAL ERROR', err) 44 | 45 | let stats = rawStats.toJson() 46 | 47 | sails.log.debug('sails-webpack: Build Info\n' + rawStats.toString({ 48 | colors: true, 49 | chunks: false 50 | })) 51 | 52 | if (stats.errors.length > 0) { 53 | sails.log.error('sails-webpack:', stats.errors) 54 | } 55 | if (stats.warnings.length > 0) { 56 | sails.log.warn('sails-webpack:', stats.warnings) 57 | } 58 | } 59 | } 60 | 61 | module.exports = Marlinspike.createSailsHook(Webpack) 62 | -------------------------------------------------------------------------------- /config/webpack.js: -------------------------------------------------------------------------------- 1 | module.exports.webpack = { 2 | } 3 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var babel = require('gulp-babel'); 3 | 4 | gulp.task('default', function () { 5 | gulp.src([ 'api/**' ]) 6 | .pipe(babel({ 7 | presets: [ 'es2015' ] 8 | })) 9 | .pipe(gulp.dest('dist/api')); 10 | 11 | gulp.src([ 'config/**.js' ]) 12 | .pipe(babel({ 13 | presets: [ 'es2015' ] 14 | })) 15 | .pipe(gulp.dest('dist/config')); 16 | }); 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sails-webpack", 3 | "version": "1.0.13", 4 | "description": "Webpack asset pipeline hook for Sails", 5 | "keywords": [ 6 | "sails", 7 | "sailsjs", 8 | "hook", 9 | "sails-hook", 10 | "webpack", 11 | "build", 12 | "asset pipeline" 13 | ], 14 | "dependencies": { 15 | "lodash": "^3.10.1", 16 | "marlinspike": "^1.0", 17 | "webpack": "^1.9.6" 18 | }, 19 | "scripts": { 20 | "prepublish": "gulp", 21 | "test": "mocha" 22 | }, 23 | "main": "dist/api/hooks/webpack/index.js", 24 | "repository": { 25 | "type": "git", 26 | "url": "git://github.com/balderdash-projects/sails-webpack.git" 27 | }, 28 | "author": { 29 | "name": "Weyland Joyner", 30 | "email": "weyland@balderdash.io" 31 | }, 32 | "contributors": [ 33 | { 34 | "name": "Joey Di Nardo", 35 | "email": "joey@balderdash.io" 36 | }, 37 | { 38 | "name": "Travis Webb", 39 | "email": "tjwebb@balderdash.io" 40 | } 41 | ], 42 | "devDependencies": { 43 | "babel-core": "^6.1.4", 44 | "babel-preset-es2015": "^6.1.4", 45 | "gulp": "^3.9.0", 46 | "gulp-babel": "^6.1.0", 47 | "mocha": "^2.3.3", 48 | "sails": "^0.11.2" 49 | }, 50 | "sails": { 51 | "isHook": true, 52 | "hookName": "webpack" 53 | }, 54 | "license": "MIT" 55 | } 56 | -------------------------------------------------------------------------------- /test/bootstrap.test.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Sails = require('sails'); 3 | var path = require('path'); 4 | var sails; 5 | 6 | before(function(done) { 7 | this.timeout(30000); 8 | 9 | var config = { 10 | appPath: path.resolve(__dirname, '..'), 11 | hooks: { 12 | grunt: false 13 | }, 14 | log: { 15 | level: 'error' 16 | } 17 | } 18 | 19 | Sails.lift(config, function(err, server) { 20 | if (err) return done(err); 21 | 22 | global.sails = server; 23 | done(err, sails); 24 | }); 25 | 26 | }); 27 | 28 | after(function(done) { 29 | global.sails.lower(done); 30 | }); 31 | -------------------------------------------------------------------------------- /test/hook.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | 3 | describe('sails-webpack Hook', function () { 4 | 5 | it('should load', function () { 6 | assert(global.sails.hooks.webpack) 7 | }) 8 | 9 | }) 10 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --recursive 2 | --compilers js:babel-core/register 3 | --------------------------------------------------------------------------------