kmck / lodash-template-webpack-loader Goto Github PK
View Code? Open in Web Editor NEWWebpack loader for Lodash templates
License: MIT License
Webpack loader for Lodash templates
License: MIT License
Hi.
First of all, sorry about my terrible English. ( almost all Japanese is. )
We are trying to transpile emdebedded javascript code from lodash/template by babel 8.
// webpack.config.js (webpack 4)
module.exports = {
devtool: 'eval-source-map'
module: {
rules: [
test: /\.tpl$/,
use: [
'babel-loader',
'lodash-template-webpack-loader'
]
},
above setting cause bable-loader Error.
Error: .inputSourceMap must be a boolean, object, or undefined
because of babel-loader does not accept SourceMap as 'string' type.
// code inside babel (sorry no link. can't Find in GitHub)
function assertInputSourceMap(loc, value) {
if (value !== undefined && typeof value !== "boolean" && (typeof value !== "object" || !value)) {
throw new Error(`${msg(loc)} must be a boolean, object, or undefined`);
}
return value;
}
I tried patch to lodash-template-webpack-loader (local).
lodash-template-webpack-loader/index.js
Line 68 in 48c67ed
// index.js
// Source map
if (!map && (this.sourceMap || params.sourceMap || options.sourceMap)) {
var sourceMapGenerator = new SourceMapGenerator({
file: this.resourcePath,
});
sourceMapGenerator.setSourceContent(this.resourcePath, content);
sourceMapGenerator.addMapping({
source: this.resourcePath,
original: {line: 1, column: 0},
generated: {line: 1, column: 0},
});
// map = sourceMapGenerator.toString(); // -> OUT
map = sourceMapGenerator.toJSON(); // <- IN
}
and works fine.
below works too, result is different however.
// webpack.config.js
rules: [
test: /\.tpl$/,
use: [
'babel-loader',
'test-loader',
'lodash-template-webpack-loader'
]
},
// test-loader.js
module.exports = function(content, map, meta) {
// this.callback(null, content, JSON.parse(map), meta); // -> cause parse Error
this.callback(null, content, null, meta);
};
We hope that this module to be available switching sourceMap type to Json object.
development works great!
but webpack build consistently fails with fallback-loader.js
can not found.
➜ npm i -D lodash-template-webpack-loader
➜ cd node_modules/lodash-template-webpack-loader/
➜ ll
total 48
-rw-r--r-- 1 iwa staff 1.1K 5 3 2016 LICENSE
-rw-r--r-- 1 iwa staff 7.2K 5 6 2016 README.md
-rw-r--r-- 1 iwa staff 6.2K 5 6 2016 index.js
drwxr-xr-x 3 iwa staff 102B 9 29 01:18 lib
drwxr-xr-x 3 iwa staff 102B 9 29 01:18 node_modules
-rw-r--r-- 1 iwa staff 2.3K 9 29 01:18 package.json
For example, html-minifier-loader
.
It's possible to specify different configurations using ?pack=subconfig
. This needs to be added to the README
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.