Skip to content

Instantly share code, notes, and snippets.

@anikethsaha
Created May 24, 2018 16:23
Show Gist options
  • Save anikethsaha/bd6ff860e9d06637ada68ee849c856b2 to your computer and use it in GitHub Desktop.
Save anikethsaha/bd6ff860e9d06637ada68ee849c856b2 to your computer and use it in GitHub Desktop.
this is simple configuration for the serverside and browserside configuration of the webpack to write es6 code .
// project structure
/*
├───node_modules
├───public
│ ├───css
│ │ normalize.css
│ │ skeleton.css
│ │ style.css
│ │
│ ├───js
│ │ jquery.min.js
│ │
│ └───views
│ index.ejs
└───src
├───browser
│ index.js
├───common
│ │ action.js
│ │ store.js
│ │
│ └───component
└───server
│ index.js
├───controller
├───middleware
└───model
│ .babelrc
│ bundle.js
│ bundle.js.map
│ package-lock.json
│ package.json
│ server.js
│ server.js.map
│ serveres5.js
│ webpack.config.js
*/
var webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
var path = require('path');
BrowserConfig = {
entry: './src/browser/index.js',
output: {
path: path.resolve(__dirname),
filename: './bundle.js',
publicPath: '/'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
devServer: {
historyApiFallback: true,
},
stats: {
colors: true
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
__isBrowser__: "true"
})
]
};
ServerConfig = {
entry: './src/server/index.js',
output: {
path: path.resolve(__dirname),
filename: './server.js',
libraryTarget: "commonjs2",
publicPath: '/'
},
node: {
__dirname: false
},
target: 'node',
externals: [nodeExternals()],
plugins: [
new webpack.DefinePlugin({
__isBrowser__: "false"
})
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
}
};
module.exports = [ BrowserConfig , ServerConfig ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment