Created
February 24, 2016 03:12
-
-
Save mastercactapus/05da17090e4a49d23173 to your computer and use it in GitHub Desktop.
webpack 2.x strict mode (with harmony imports)
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
"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