2016-04-07 4 views
4

Когда я использую Webpack связать мои JS файлы,Webpack Uncaught ошибка синтаксиса: Неожиданный токен <

Во-первых, когда команда webpack я бегу с помощью НПМ на CMD затем создаются 2 пучка файлов, а именно bundle.js и 1.bundle.js. Это нормально, что создаются 2 файла пакета?

Во-вторых, когда я использую bundle.js в моем index.html то загружается и 1.bundle.js также загружается на странице, но 1.bundle.js модифицируется нравится HTML-файл с различными сценариями тегов. Это тоже нормально?

В-третий он показывает ошибку в консоли, что Uncaugh syntax error: Unexpected token < в файл 1.bundle.js т.е. когда он читает 1.bundle.js то начать читать <!DOCTYPE HTML> содержащиеся в начале файла и показывает ошибку, < в <!DOCTYPE HTML> является неожиданным. Любая помощь будет высоко оценен супер

bundle.js

/******/ (function(modules) { // webpackBootstrap 
    /******/ // install a JSONP callback for chunk loading 
    /******/ var parentJsonpFunction = window["webpackJsonp"]; 
    /******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) { 
    /******/  // add "moreModules" to the modules object, 
    /******/  // then flag all "chunkIds" as loaded and fire callback 
    /******/  var moduleId, chunkId, i = 0, callbacks = []; 
    /******/  for(;i < chunkIds.length; i++) { 
    /******/   chunkId = chunkIds[i]; 
    /******/   if(installedChunks[chunkId]) 
    /******/    callbacks.push.apply(callbacks, installedChunks[chunkId]); 
    /******/   installedChunks[chunkId] = 0; 
    /******/  } 
    /******/  for(moduleId in moreModules) { 
    /******/   modules[moduleId] = moreModules[moduleId]; 
    /******/  } 
    /******/  if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules); 
    /******/  while(callbacks.length) 
    /******/   callbacks.shift().call(null, __webpack_require__); 

    /******/ }; 

    /******/ // The module cache 
    /******/ var installedModules = {}; 

    /******/ // object to store loaded and loading chunks 
    /******/ // "0" means "already loaded" 
    /******/ // Array means "loading", array contains callbacks 
    /******/ var installedChunks = { 
    /******/  0:0 
    /******/ }; 

    /******/ // The require function 
    /******/ function __webpack_require__(moduleId) { 

    /******/  // Check if module is in cache 
    /******/  if(installedModules[moduleId]) 
    /******/   return installedModules[moduleId].exports; 

    /******/  // Create a new module (and put it into the cache) 
    /******/  var module = installedModules[moduleId] = { 
    /******/   exports: {}, 
    /******/   id: moduleId, 
    /******/   loaded: false 
    /******/  }; 

    /******/  // Execute the module function 
    /******/  modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 

    /******/  // Flag the module as loaded 
    /******/  module.loaded = true; 

    /******/  // Return the exports of the module 
    /******/  return module.exports; 
    /******/ } 

    /******/ // This file contains only the entry chunk. 
    /******/ // The chunk loading function for additional chunks 
    /******/ __webpack_require__.e = function requireEnsure(chunkId, callback) { 
    /******/  // "0" is the signal for "already loaded" 
    /******/  if(installedChunks[chunkId] === 0) 
    /******/   return callback.call(null, __webpack_require__); 

    /******/   script.src = __webpack_require__.p + "" + chunkId + ".bundle.js"; 
    /******/   head.appendChild(script); 
    /******/  } 
    /******/ }; 

    /******/ // expose the modules object (__webpack_modules__) 
    /******/ __webpack_require__.m = modules; 

    /******/ // expose the module cache 
    /******/ __webpack_require__.c = installedModules; 

    /******/ // __webpack_public_path__ 
    /******/ __webpack_require__.p = ""; 

    /******/ // Load entry module and return exports 
    /******/ return __webpack_require__(0); 
    /******/ }) 
    /************************************************************************/ 
    /******/ ([ 
    /* 0 */ 
    /***/ function(module, exports, __webpack_require__) { 

     __webpack_require__.e/* require */(1, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [ 
      // Load our app module and pass it to our definition function 
      __webpack_require__(1), 

     ]; (function(test){ 
      test.init(); 
     }.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));}); 
     //saksham was here 

    /***/ } 
    /******/ ]); 

1.bundle..js

webpackJsonp([1],[ 
    /* 0 */, 
    /* 1 */ 
    /***/ function(module, exports, __webpack_require__) { 

     var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [ 
      __webpack_require__(3), 
      __webpack_require__(20), 
      __webpack_require__(14), 
      __webpack_require__(15), 
      __webpack_require__(16), 
      __webpack_require__(17), 
      __webpack_require__(6), 
      __webpack_require__(11), 
      __webpack_require__(29), 
      __webpack_require__(32), 
      __webpack_require__(33) 

     ], __WEBPACK_AMD_DEFINE_RESULT__ = function($, jPlayer, d_qtip_2, emotify, colorpicker, fileattachment){ 

      var init = function() { 
      $(document).ready(function(){ 
       if(typeof(window.xxxx)==="function") { 
       window.xxxx(); 
       console.log("saksham is a virus"); 
       } 
       xxx.xxxx(); 
       if(!(xxxx.checkMobile() && xxxx.embed.id === false && xxxx.app.mobile_web === '1')){ 
       xxxx.init(); 
       xxxx.init(); 
       } 
       else{ 
       xxxx.emit('mobileButtonLoad', []); 
       } 

      }); 

      aaaa.on('ChatDisconnected', function() { 
       if(xxxx.app.chatAccess) { 
       xxxx.init(); 
       } 
       else{ 
       $('#drupalchat-wrapper').hide(); 
       //console.log('hidden'); 
       //console.log(xxx.frontend.altrovr); 
       if(xxx.frontend.altrovr == true){ 
        $("#drupalchat-altrovr").show(); 
        $("#drupalchat").hide(); 
       } 
       } 
      }); 
      }; 

      return { 
      'init': init 
      }; 


     }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); 

...etc 

Теперь 1.bundle.js получает измененную к этому. Я скопировал его из раздела сетей рядом с консолью в браузере

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" 
    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr" 
    xmlns:content="http://purl.org/rss/1.0/modules/content/" 
    xmlns:dc="http://purl.org/dc/terms/" 
    xmlns:foaf="http://xmlns.com/foaf/0.1/" 
    xmlns:og="http://ogp.me/ns#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:sioc="http://rdfs.org/sioc/ns#" 
    xmlns:sioct="http://rdfs.org/sioc/types#" 
    xmlns:skos="http://www.w3.org/2004/02/skos/core#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> 

<head profile="http://www.w3.org/1999/xhtml/vocab"> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="shortcut icon" href="http://web.iflychatdev.com:12000/websites/t3/misc/favicon.ico" type="image/vnd.microsoft.icon" /> 
<link rel="shortlink" href="/websites/t3/node/1" /> 
<link rel="canonical" href="/websites/t3/node/1" /> 
<meta name="Generator" content="Drupal 7 (http://drupal.org)" /> 
    <title>iflychat-require-app | T3</title> 
    <style type="text/css" media="all"> 
</style> 
<style type="text/css" media="all"> 
</style> 
<style type="text/css" media="all"> 

</style> 
<style type="text/css" media="all"> 
@import 

...etc 

Теперь это нормально ?? что файл будет изменен

И как избавиться от этой ошибки неожиданного лексемы <

пса: Я проникаю мое приложение из requirejs в WebPack

webpack.config.js

var path = require('path'); 

module.exports = { 
    //our config 
    context: path.resolve(__dirname, 'require'), 
    entry: './iflychat-main', 
    output: { 
    path: path.resolve('./dist'), 
    filename: 'bundle.js' 
    }, 
    resolve: { 
    modulesDirectories: ['.','./require/libs'], 
    }, 
} 
+0

Введите WebPack конф. –

+0

добавлен файл 'webpack.config' – iamsaksham

+0

' bundle.js' запрашивается у '[сайта]/websites/t3/iflychat-app/require/bundle.js' и' 1.bundle.js' с '[сайта]/веб-сайтов/t3/node/1.bundle.js', поэтому этот файл не может быть найден, а те '' являются только страницей Drupal 404. –

ответ

4

Main расслоения плотного файл bundle.js, пытаясь запросить куски от url, сгенерированного таким образом:

script.src = __webpack_require__.p + "" + chunkId + ".bundle.js"; 

, где __webpack_require__.p является общедоступной дорогой в Интернете.

Это означает, что куски будут загружаться с пути относительно документа (/websites/t3/node/). Но так как ваши файлы находятся в /websites/t3/iflychat-app/require/, куски не будут загружены должным образом.

Таким образом, решение указать правильный путь к Js активов:

module.exports = { 
    ... 
    output: { 
    path: path.resolve('./dist'), 
    publicPath: '/websites/t3/iflychat-app/require/', 
    filename: 'bundle.js' 
    }, 
    ... 
} 
Смежные вопросы