2015-08-12 33 views
8

Sto convertendo un progetto usando requirejs nel webpack e avendo problemi con il caricatore "html-loader".Webpack non può risolvere html-loader

package.json:

"html-loader": "^0.3.0", 
"webpack": "^1.11.0", 
"webpack-dev-server": "^1.10.1" 

app/js/webpack.config.js:

// folder structure: 
    // root 
    // app/js 
    // bower_components/ 
    // dist/ 
    // node_modules/ 

    entry: './app/js/main.js', 
    output: { 
    path: 'dist/js/', 
    filename: 'bundle.js', 
    }, 
    module: { 
    loaders: [ 
     // Note, via requirejs's "text" plugin, I included templates 
     // like this: var tpl = require('text!sample.html'); 
     // For webpack, I went through the codebase and cleaned up 
     // every instance of "text!". 
     {test: /\.html$/, loader: 'html'} 
    ] 
    }, 
    resolve: { 
    root: ['app/js', 'bower_components'], 
    alias: { 
     ... 
    } 
    }, 
    plugins: [ 
    new webpack.ResolverPlugin(
     new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
     'bower.json', ['main'] 
    ) 
    ) 
    ] 

Quando eseguo webpack - webpack --config app/js/webpack.config.js - ottengo il seguente messaggio di errore:

ERROR in app/js/some/file.js
Module not found: Error: Cannot resolve module 'html' in app/js/some/file.js

Ho provato quanto segue, che non ha funzionato:

resolveLoader: { 
    root: [path.join(__dirname, 'node_modules')], 
    }, 

Ha anche provato a spostare "webpack.config.js" nella radice del progetto. Neanche questo ha aiutato.

E, anche provato a utilizzare il caricatore "caricatore raw", che ha anche provocato lo stesso errore "Impossibile risolvere il modulo 'raw'".

Qualsiasi aiuto sarebbe apprezzato. Grazie.

+0

è possibile includere i tuoi 'app/js/some/file.js' qui? – lanan

+0

Ci scusiamo per una domanda stupida, ma sei assolutamente sicuro che ** html-loader ** e ** raw-loader ** siano installati correttamente? Forse ti manca qualche errore quando esegui 'npm install'? – Kreozot

risposta

0

Completamente lasciato cadere la palla per l'aggiornamento.

1) Avrei dovuto usare text-loader, che mi consente di lasciare in posizione ogni require('text!some/template.html');.

2) Il percorso principale era not absolute. Secondo il manuale, "Deve essere un percorso assoluto! Non passare qualcosa come ./app/modules".

3) Se il tuo require s assomiglia a require('text!some/file.html'), allora hai finito. La definizione del caricatore in webpack.config.js è ridondante. Se lo fai, i tuoi modelli avranno l'aspetto di module.exports="module.exports=\"...\"".

Aggiornato config:

entry: './app/js/main.js', 
output: { 
    path: 'dist/js/', 
    filename: 'bundle.js', 
}, 
module: { 
    loaders: [/*nothing*/] 
}, 
resolve: { 
    root: [ 
     path.resolve('app/js'), 
     path.resolve('bower_components') 
    ], 
    alias: { 
     ... 
    } 
}, 
plugins: [ 
    new webpack.ResolverPlugin(
     new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
      'bower.json', ['main'] 
     ) 
    ) 
] 
Problemi correlati