1.0.5 • Published 2 years ago

simple-lodash-template-loader v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simple-lodash-template-loader

Support Webpack both 4 and 5 , A loader for webpack that allows importing files as a lodash template.

Features

  • Support Webpack 4 and 5.

Getting Started

To begin, you'll need to install simple-lodash-template-loader:

npm install simple-lodash-template-loader --save-dev
# or
yarn add -D simple-lodash-template-loader

Then add the loader to your webpack config. For example:

file.js

import compiled from './file.t.html'

webpack.config.js

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.t\.html$/i,
        use: 'simple-lodash-template-loader'
      }
    ]
  }
}

Options

NameTypeDefaultDescription
escape{RegExp}_.templateSettings.escapeThe HTML "escape" delimiter.
evaluate{RegExp}_.templateSettings.evaluateThe "evaluate" delimiter.
imports{Object}_.templateSettings.importsAn object to import into the template as free variables.
interpolate{RegExp}_.templateSettings.interpolateThe "interpolate" delimiter.
sourceURL{string}'lodash.templateSources[n]'The sourceURL of the compiled template.
variable{string}'obj'The data object variable name.
callback{Fuction}(this: webpack.LoaderContext<LoaderOptions>,contents: string) => TemplateOptionscallback function allow you customize your templateSettings for each lodash templete file, the return options will be merged to root options
esModule{Boolean}falseUses ES modules syntax

Tips

To support the 'esModule' option, the 'variable' option must be passed to avoid 'with' statements in the compiled template to be strict mode compatible.
Please see https://github.com/lodash/lodash/issues/3709#issuecomment-375898111.
To enable CommonJS, please set the 'esModule' option to false (default false).

License

MIT