Last active
January 14, 2020 16:26
-
-
Save oxpa/09b3ef3c289272ced8c7eba77c8a1f88 to your computer and use it in GitHub Desktop.
webpack configuration suitable for static content generator plugin and chunks
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
var path = require('path'); | |
var StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin') | |
var ExtractTextPlugin = require('extract-text-webpack-plugin') | |
var webpack = require('webpack'); | |
var urlloader = require('url-loader'); | |
var React = require("react"); | |
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"); | |
function walkSync(currentDirPath, callback) { | |
var fs = require('fs'), | |
path = require('path'); | |
fs.readdirSync(currentDirPath).forEach(function (name) { | |
var filePath = path.join(currentDirPath, name); | |
var stat = fs.statSync(filePath); | |
if (stat.isFile()) { | |
callback(filePath, stat); | |
} else if (stat.isDirectory()) { | |
callback(filePath, stat); | |
walkSync(filePath, callback); | |
} | |
}); | |
} | |
var window={} | |
var getElementsByTagName = function (b) { | |
return [{appendChild:function (c){ | |
global['webpackJsonp'] = window['webpackJsonp']; | |
global['React']=React; | |
getAsset(c.src) | |
}}] | |
} | |
var createElement = function (t) {return {}} | |
var locals = { | |
paths: [ | |
'/' | |
,'/login' | |
,'/about' | |
,'/svcs' | |
,'/remind' | |
,'/register' | |
,'/reset' | |
,'/download' | |
], | |
scope:{ | |
React:React, | |
ReactDom:ReactDom, | |
Redux:Redux, | |
ReactRedux:ReactRedux, | |
ReactRouter:ReactRouter | |
//,window:window | |
//,webpackJsonp: function(){} | |
//,document:{ | |
// getElementsByTagName:getElementsByTagName, | |
// createElement:createElement | |
// } | |
//documentElement:["classList"]}, | |
//Element:{prototype:{matches:false}} | |
} | |
} | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false, | |
properties: true, | |
sequences: true, | |
dead_code: true, | |
conditionals: true, | |
comparisons: true, | |
evaluate: true, | |
booleans: true, | |
unused: true, | |
loops: true, | |
hoist_funs: true, | |
cascade: true, | |
if_return: true, | |
join_vars: true, | |
//drop_console: true, | |
drop_debugger: true, | |
negate_iife: true, | |
unsafe: true, | |
hoist_vars: true, | |
//side_effects: true | |
} | |
//,sourceMap: true | |
}); | |
module.exports = { | |
//node: {process:false}, | |
entry: {main:['./main.js'], bundle:['./index.js'], style:['./style.scss']}, | |
output: { | |
path: __dirname +'/compiled/' | |
,chunkFilename: "[name].js" | |
,filename: '[name].js' | |
,libraryTarget: 'umd' | |
,chunkLoadTimeout: 120000 | |
,publicPath: "/js/" | |
}, | |
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: { | |
//root: [path.resolve('./compiled/')], | |
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,true), | |
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