小编Tsa*_*arS的帖子

Webpack 和 svg-inline-loader 不起作用

我尝试svg-inline-loader在多页项目中使用。

当我在索引页面上使用它时它工作正常

    <%= require('!svg-inline- loader!../../img/toolbar/'+firstBtn.iconName+'.svg') %>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将它注入部分文件时,它不起作用。我得到

     Html Webpack Plugin:
     ReferenceError: require is not defined

    - lodash.templateSources[16]:7 eval
      lodash.templateSources[16]:7:50

    - loader.js:31 eval
      [search.html?..]/[html-webpack-plugin]/lib/loader.js:31:106

    - loader.js:36 module.exports
      [search.html?..]/[html-webpack-plugin]/lib/loader.js:36:3

    - index.js:422 
      [site.local]/[html-webpack-plugin]/index.js:422:16
Run Code Online (Sandbox Code Playgroud)

我的 webpack 配置

    {
      test: /\.html$/,
      include: [path.resolve('src/html/partials/')],
      use: ['html-loader']
        },           
      new HtmlWebpackPlugin({
       filename: 'index.html',
       template: './html/pages/index.html',
       chunks: ['main']
       }),
      new HtmlWebpackPlugin({
       filename: 'login.html',
       template: './html/pages/login.html',
       chunks: ['login', 'main']
       }),
      new HtmlWebpackPlugin({
       filename: 'search.html',
       template: './html/pages/search.html',
       chunks: ['main']
       }),
Run Code Online (Sandbox Code Playgroud)

我的搜索页面

     <% var toolbar = {
       firstBtn: {
       title: …
Run Code Online (Sandbox Code Playgroud)

javascript svg node.js ecmascript-6 webpack

5
推荐指数
1
解决办法
529
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

node.js ×1

svg ×1

webpack ×1