Created
September 27, 2018 13:42
-
-
Save cxspxr/0522192030ff7a1c79e729060491bd2b to your computer and use it in GitHub Desktop.
Webpack CoffeeScript + PostCSS (SugarSS) + Stylus +
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const rupture = require('rupture') | |
const isDev = process.argv.indexOf('-p') === -1 | |
let removeNull = array => array.filter(e => e !== null) | |
module.exports = { | |
output: { | |
path: path.resolve('./dist'), | |
filename: 'bundle.js', | |
publicPath: '' | |
}, | |
resolve: { | |
extensions: [ | |
'.coffee', | |
'.js', | |
'.json', | |
isDev ? '.dev.coffee' : '.prod.coffee', | |
isDev ? '.dev.js' : '.prod.js', | |
], | |
modules: ['node_modules', path.resolve('./src')] | |
}, | |
devtool: 'source-map', | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
include: path.resolve('./src'), | |
use: ['babel-loader'] | |
}, | |
{ | |
test: /\.coffee$/, | |
include: path.resolve('./src'), | |
use: ['babel-loader', 'coffee-loader'] | |
}, | |
{ | |
test: /\.(png|svg|jpg|jpeg|gif)$/, | |
include: path.resolve('./src/assets'), | |
use: [ | |
{ | |
loader: 'file-loader', | |
options: isDev | |
? { | |
// use full path in development for better readability | |
name: '[path][name].[ext]' | |
} | |
: { | |
outputPath: 'assets/' | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.(css)$/, | |
include: path.resolve('./src'), | |
use: ['style-loader', 'css-loader'] | |
}, | |
{ | |
test: /\.(sss)$/, | |
include: path.resolve('./src'), | |
use: removeNull([ | |
'style-loader', | |
{ | |
loader: 'css-loader', | |
options: { | |
localIdentName: isDev | |
? '[name]_[local]_[hash:base64:3]' | |
: '[hash:base64:10]', | |
modules: true, | |
importLoaders: 1 | |
} | |
}, | |
isDev ? null : 'postcss-loader', | |
{ | |
loader: 'stylus-loader', | |
options: { | |
sourceMap: isDev, | |
use: [rupture()] | |
} | |
}, | |
isDev ? 'postcss-loader?parser=sugarss' : null | |
]) | |
} | |
] | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const merge = require('webpack-merge') | |
const common = require('./webpack.common.js') | |
const path = require('path') | |
const HtmlWebpackPlugin = require('html-webpack-plugin') | |
const { | |
NamedModulesPlugin, | |
HotModuleReplacementPlugin | |
} = require('webpack') | |
module.exports = merge(common, { | |
entry: ['react-hot-loader/patch', './src/index.dev.coffee'], | |
devtool: 'eval', | |
devServer: { | |
contentBase: path.resolve('./dist'), | |
historyApiFallback: true, | |
hot: true, | |
proxy: { | |
'/api': 'http://localhost:3000' | |
} | |
}, | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
template: path.resolve('./public/index.html'), | |
inject: 'body' | |
}), | |
new NamedModulesPlugin(), | |
new HotModuleReplacementPlugin() | |
] | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const merge = require('webpack-merge') | |
const common = require('./webpack.common.js') | |
const path = require('path') | |
const HtmlWebpackPlugin = require('html-webpack-plugin') | |
const CleanWebpackPlugin = require('clean-webpack-plugin') | |
const {DefinePlugin} = require('webpack') | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
module.exports = merge(common, { | |
entry: './src/index.prod.coffee', | |
devtool: 'nosources-source-map', | |
plugins: [ | |
new CleanWebpackPlugin(['dist']), | |
new HtmlWebpackPlugin({ | |
template: path.resolve('./public/index.html'), | |
inject: 'body', | |
minify: { | |
removeComments: true, | |
collapseWhitespace: true, | |
conservativeCollapse: true | |
} | |
}), | |
new UglifyJsPlugin, | |
new DefinePlugin({ | |
'process.env': { | |
NODE_ENV: JSON.stringify('production') | |
} | |
}) | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment