Initial migration to webpack
parent
a852394bd9
commit
38da5b0d41
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,35 @@
|
|||||||
|
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||||
|
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||||
|
|
||||||
|
function MyUmdPlugin(options) {
|
||||||
|
this.name = options.library;
|
||||||
|
console.log(this.name);
|
||||||
|
}
|
||||||
|
module.exports = MyUmdPlugin;
|
||||||
|
MyUmdPlugin.prototype.apply = function(compiler) {
|
||||||
|
compiler.plugin("this-compilation", function(compilation) {
|
||||||
|
var mainTemplate = compilation.mainTemplate;
|
||||||
|
console.log("Compilation: " + (typeof compilation.templatesPlugin));
|
||||||
|
compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
|
||||||
|
|
||||||
|
var amdFactory = "factory";
|
||||||
|
return new ConcatSource(new OriginalSource(
|
||||||
|
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
|
||||||
|
" if(typeof exports === 'object' && typeof module === 'object')\n" +
|
||||||
|
" module.exports = factory(factory.toString());\n" +
|
||||||
|
" else if(typeof exports === 'object')\n" +
|
||||||
|
" exports[\"" + this.name + "\"] = factory(factory.toString());\n" +
|
||||||
|
" else\n" +
|
||||||
|
" root[\"" + this.name + "\"] = factory(factory.toString());\n" +
|
||||||
|
"})(this, function(__factorySource__) {\nreturn ", "webpack/myModuleDefinition"), source, "\n});\n");
|
||||||
|
}.bind(this));
|
||||||
|
mainTemplate.plugin("global-hash-paths", function(paths) {
|
||||||
|
if(this.name) paths = paths.concat(this.name);
|
||||||
|
return paths;
|
||||||
|
}.bind(this));
|
||||||
|
mainTemplate.plugin("hash", function(hash) {
|
||||||
|
hash.update("umd");
|
||||||
|
hash.update(this.name + "");
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this));
|
||||||
|
};
|
@ -1,40 +0,0 @@
|
|||||||
/* jshint undef: true, unused: true, browser:true, devel: true */
|
|
||||||
/* global define */
|
|
||||||
|
|
||||||
define([], function() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function createNode(htmlStr) {
|
|
||||||
var temp = document.createElement('div');
|
|
||||||
|
|
||||||
temp.innerHTML = htmlStr;
|
|
||||||
while (temp.firstChild) {
|
|
||||||
return temp.firstChild;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeObjects(obj1, obj2) {
|
|
||||||
for (var p in obj2) {
|
|
||||||
try {
|
|
||||||
if (obj2[p].constructor == Object) {
|
|
||||||
obj1[p] = mergeObjects(obj1[p], obj2[p]);
|
|
||||||
} else {
|
|
||||||
obj1[p] = obj2[p];
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
obj1[p] = obj2[p];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
createNode : function(htmlStr) {
|
|
||||||
return createNode(htmlStr);
|
|
||||||
},
|
|
||||||
mergeObjects : function(obj1, obj2) {
|
|
||||||
return mergeObjects(obj1, obj2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
@ -0,0 +1,34 @@
|
|||||||
|
var webpack = require('webpack'),
|
||||||
|
MyUmdPlugin = require('./plugins/umd');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: [
|
||||||
|
'./src/quagga.js'
|
||||||
|
],
|
||||||
|
devtool: 'source-map',
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.jsx?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['', '.js', '.jsx']
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: __dirname + '/dist',
|
||||||
|
publicPath: '/',
|
||||||
|
filename: 'quagga.js',
|
||||||
|
sourceMapFilename: 'quagga.map'
|
||||||
|
},
|
||||||
|
devServer: {
|
||||||
|
contentBase: './',
|
||||||
|
hot: true
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new MyUmdPlugin({
|
||||||
|
library: 'Quagga'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
@ -0,0 +1,8 @@
|
|||||||
|
var webpack = require('webpack');
|
||||||
|
module.exports = require('./webpack.config.js');
|
||||||
|
|
||||||
|
module.exports.plugins.unshift(
|
||||||
|
new webpack.optimize.UglifyJsPlugin()
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports.output.filename = 'quagga.min.js';
|
Loading…
Reference in New Issue