@a8k/nunjucks-loader 中文文档教程

发布于 3年前 浏览 19 更新于 3年前

@a8k/nunjucks-loader

原来的'nunjucks-html-loader'不支持相对搜索路径,webpack4有警告。 所以,我叉它

Usage

install

npm i -D @a8k/nunjucks-loader

webpack rules

const configureHtmlLoader = ({ mini, projectDir }) => {
  return {
    test: /\.(html|njk|nunjucks)$/,
    use: [
      {
        loader: resolve('html-loader'),
        options: {
          minimize: mini && env.NODE_ENV === PROD,
        },
      },
      {
        loader: resolve('@a8k/nunjucks-loader'),
        options: {
          // Other super important. This will be the base
          // directory in which webpack is going to find
          // the layout and any other file index.njk is calling.
          // default search path is current resource path
          searchPaths: ['./src', './src/pages', './src/assets'].map(i => path.join(projectDir, i)),
        },
      },
    ],
  };
};

@a8k/nunjucks-loader

The original 'nunjucks-html-loader' not support relative search path and webpack4 has warning. So, I fork it

Usage

install

npm i -D @a8k/nunjucks-loader

webpack rules

const configureHtmlLoader = ({ mini, projectDir }) => {
  return {
    test: /\.(html|njk|nunjucks)$/,
    use: [
      {
        loader: resolve('html-loader'),
        options: {
          minimize: mini && env.NODE_ENV === PROD,
        },
      },
      {
        loader: resolve('@a8k/nunjucks-loader'),
        options: {
          // Other super important. This will be the base
          // directory in which webpack is going to find
          // the layout and any other file index.njk is calling.
          // default search path is current resource path
          searchPaths: ['./src', './src/pages', './src/assets'].map(i => path.join(projectDir, i)),
        },
      },
    ],
  };
};
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文