Skip to content

Instantly share code, notes, and snippets.

@Evshved
Last active February 6, 2018 13:40
Show Gist options
  • Select an option

  • Save Evshved/f53cf10b8a48c240e0ba1ea111221fcb to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/f53cf10b8a48c240e0ba1ea111221fcb to your computer and use it in GitHub Desktop.
1.js
const webpack = require('webpack');
const koa = require('koa');
const koaWebpack = require('koa-webpack');
const webpackConfig = require('../client/webpack.config.js');
const router = require('koa-router');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.on('unhandledRejection', (reason, p) => {
});
const app = new koa();
const koaRouter = new router();
app.use(koaWebpack({
compiler: webpack(webpackConfig),
hot: {},
dev: {
publicPath: webpackConfig.output.publicPath,
},
}));
app
.use(koaRouter.routes())
.use(koaRouter.allowedMethods());
koaRouter.get('/', (ctx, next) => {
ctx.body = 'Hello World!';
});
app.listen(3001, () => {
});
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: [
'./index.js',
],
},
output: {
path: `${__dirname}/client/`,
publicPath: '/client/',
filename: '[name].js',
},
context: path.resolve(__dirname, './'),
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.pcss$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
camelCase: true,
localIdentName: '[local]_[hash:base64:5]',
},
},
{ loader: 'postcss-loader' },
],
},
],
},
devtool: 'eval',
resolve: {
modules: ['./', 'node_modules'],
extensions: ['.js', '.jsx', '.pcss'],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, './index.html')
})]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment