Skip to content

Instantly share code, notes, and snippets.

@fuunnx
Forked from oxpa/webpack.config.js
Created November 6, 2016 18:01
Show Gist options
  • Save fuunnx/dcc393af15c292f3392c1d2a3804e6d8 to your computer and use it in GitHub Desktop.
Save fuunnx/dcc393af15c292f3392c1d2a3804e6d8 to your computer and use it in GitHub Desktop.
webpack configuration suitable for static content generator plugin and chunks
var ReactDom = require("react-dom");
var Redux = require("redux");
var ReactRouter = require("react-router");
var ReactRedux = require("react-redux");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var window={}
var getElementsByTagName = function (b) {
return [{appendChild:function (c){
global['webpackJsonp'] = window['webpackJsonp'];
global['React']=React;
console.log(c);
require('./compiled/'+c.src);
}}]
}
var createElement = function (t) {return {}}
var locals = {
paths: [
'/'
,'/login'
,'/about'
,'/svcs'
,'/remind'
,'/register'
,'/reset'
],
scope:{
React:React,
ReactDom:ReactDom,
Redux:Redux,
ReactRedux:ReactRedux,
ReactRouter:ReactRouter
,window:{}
,webpackJsonp: function(){}
,document:{
getElementsByTagName:getElementsByTagName,
createElement:createElement
}
//documentElement:["classList"]},
//Element:{prototype:{matches:false}}
}
}
module.exports = {
//node: {process:false},
entry: {bundle:['./index.js'], main:['./main.js'], style:['./style.scss']},
output: {
path: __dirname +'/compiled/',
chunkFilename: "[name].js",
filename: '[name].js',
libraryTarget: 'umd'
,chunkLoadTimeout: 120000
},
externals: { "react": "React", "redux": "Redux", "react-dom":"ReactDom", "react-redux":"ReactRedux", "react-router":"ReactRouter"},// "flickity":"Flickity"},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style","css!postcss!sass")
},
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['react', 'stage-2','es2015-native-modules'],
plugins: ["transform-object-rest-spread","transform-object-assign"]
}
}
]
},
resolve: {
extensions: ["", ".js", "jsx", "js6"],
alias: { /*need these for flickity*/
'eventEmitter/EventEmitter': 'wolfy87-eventemitter/EventEmitter',
'get-style-property': 'desandro-get-style-property',
'matches-selector': 'desandro-matches-selector',
'classie': 'desandro-classie'
}
},
plugins: [
new StaticSiteGeneratorPlugin('main', locals.paths, locals,locals.scope),
new ExtractTextPlugin('css/[name].css', {
allChunks: true
})
],
postcss: function () {
return [require('autoprefixer')];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment