Skip to content

Instantly share code, notes, and snippets.

@albizures
Last active November 23, 2016 19:04
Show Gist options
  • Save albizures/658c8cc69d0e6ad83cbac3386bae96b8 to your computer and use it in GitHub Desktop.
Save albizures/658c8cc69d0e6ad83cbac3386bae96b8 to your computer and use it in GitHub Desktop.
sails config
{
"presets": ["es2015"],
"plugins": [
"transform-es2015-block-scoping",
"transform-es2015-destructuring",
"transform-es2015-computed-properties",
"transform-es2015-shorthand-properties"
]
}
{
"generators": {
"modules": {}
},
"hooks": {
"grunt": false
}
}
{
"watch": [
"api/**/*",
"config/**/*"
]
}
npm install --save-dev concurrently nodemon
npm install --save-dev eslint-loader eslint eslint-config-standard eslint-plugin-standard eslint-plugin-promise
npm install --save-dev babel-core babel-eslint babel-plugin-transform-es2015-block-scoping babel-plugin-transform-es2015-computed-properties babel-plugin-transform-es2015-destructuring babel-plugin-transform-es2015-shorthand-properties babel-preset-es2015
npm install --save-dev webpack-dev-server webpack babel-loader css-loader file-loader html-webpack-plugin extract-text-webpack-plugin pug-loader pug style-loader stylus stylus-loader
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const isProd = process.env.NODE_ENV === 'production';
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const publicPath = path.resolve(__dirname, './public');
const entry = [
path.join(publicPath, '/js/index.js')
];
const plugins = [
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin('[name].css', {
allChunks: true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js',
minChunks: isExternal
}),
new HtmlWebpackPlugin({
title: 'Demo',
filename: 'index.html',
template: path.join(publicPath, 'templates', process.env.NODE_ENV + '.pug')
})
];
if (isProd) {
// Minify bundle (javascript and css)
plugins.push(new webpack.optimize.UglifyJsPlugin({
minimize: true,
output: { comments: false },
compress: { drop_console: true }
}));
} else {
// add this entries in order to enable webpack HMR in browser
entry.push('webpack/hot/dev-server');
entry.push('webpack-dev-server/client?http://localhost:3000/');
// HMR plugin
plugins.push(new webpack.HotModuleReplacementPlugin({
multiStep: true
}));
plugins.push(new webpack.optimize.DedupePlugin())
plugins.push(new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}));
}
module.exports = {
entry: entry,
output: {
path: path.resolve(__dirname, '../.tmp/public'),
filename: 'bundle.js'
},
devtool: isProd ? undefined : 'source-map',
// debug: !isProd,
plugins: plugins,
module: {
loaders: [{
test: /\.js$/,
loader: 'babel'
}, {
test: /\.(jpg|jpeg|png|gif|svg)$/i,
loaders: [
'file?name=images/[name].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}, {
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file?name=/fonts/[name].[ext]'
}, {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file?name=fonts/[name].[ext]'
}, {
test: /\.pug$/,
loader: 'pug'
}, {
test: /\.css?$/,
loader: ExtractTextPlugin.extract('style', 'css')
}, {
test: /\.styl?$/,
loader: ExtractTextPlugin.extract('style', 'css!stylus')
}],
preLoaders: [{
test: /\.js?$/,
exclude: [/.tmp/, /node_modules/],
loaders: ['standard']
}]
},
standard: {
parser: 'babel-eslint'
},
devServer: {
stats: 'errors-only',
historyApiFallback: true,
port: 3000,
hot: true,
contentBase: path.resolve(__dirname, '../.tmp/public'),
proxy: {
'*': {
target: 'http://localhost:1337'
}
}
}
};
function isExternal(module) {
var userRequest = module.userRequest;
if (typeof userRequest !== 'string') {
return false;
}
if (userRequest.indexOf(/\.css?$/) >= 0) {
return false;
}
return userRequest.indexOf('/node_modules/') >= 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment