Skip to content

Instantly share code, notes, and snippets.

@mastercactapus
Created February 24, 2016 03:12
Show Gist options
  • Save mastercactapus/05da17090e4a49d23173 to your computer and use it in GitHub Desktop.
Save mastercactapus/05da17090e4a49d23173 to your computer and use it in GitHub Desktop.
webpack 2.x strict mode (with harmony imports)
"use strict";
var ConcatSource = require("webpack-sources").ConcatSource;
class StrictPlugin {
constructor(options){
this.options = options;
}
apply(compiler) {
compiler.plugin("compilation", compilation=>{
compilation.moduleTemplate.plugin("render", (moduleSource, module, chunk, dependencyTemplates)=>{
if (module.resource && module.resource.startsWith(this.options.root)) {
return new ConcatSource("\"use strict\";\n", moduleSource);
}
return moduleSource;
});
compilation.moduleTemplate.plugin("hash", hash=>{
hash.update("StrictPlugin");
hash.update("1");
});
});
}
}
module.exports = {
entry: "./lib/main",
output: {
path: __dirname + "/dist",
filename: 'bundle.js'
},
plugins: [
new StrictPlugin({ root: __dirname+"/lib" })
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment