2016-11-14 25 views
9

क्या वेबपैक मॉड्यूल लोडिंग के बिना पैकिंग के लिए वेबपैक का उपयोग करना संभव है?वेबपैक के बिना वेबपैक टाइपस्क्रिप्ट संकलन जेसनपी

मैं एक ऐप्लिकेशन है जो इस एप्लिकेशन को मैं एक छोटे से टाइपप्रति फ़ाइल test.ts कि संकलित किया जाना चाहिए है, न्यूनतम किया गया, आदि के लिए webpack का सब कुछ और अगले उपयोग कर सकते हैं लेकिन उत्पादन एक सरल js फ़ाइल कि webpackJsonp में लपेटा नहीं है होना चाहिए । क्या कुछ बाहरी लाइनों के लिए रास्ता बहुत अधिक ओवरहेड (9 6 केबी) जोड़ रहा है जिसमें बाहरी निर्भरता नहीं है।

test.ts

alert('foo'); 

test.js

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

    __webpack_require__(1); 
    __webpack_require__(75); 
    module.exports = __webpack_require__(105); 

/***/ }, 

/***/ 105: 
/***/ function(module, exports) { 

    "use strict"; 
    alert('test'); 

/***/ } 
}); 

test.js चाहिए

alert('foo'); 
है

मैं एक पारिस्थितिकी तंत्र (वेबपैक) बनाने के लिए प्रयास करने की कोशिश करता हूं।

+0

क्या आप हमें अपनी वेबपैक कॉन्फ़िगरेशन प्रदान कर सकते हैं? ऐसा लगता है कि वहां शायद कुछ ऐसा है जो बड़ी मात्रा में ओवरहेड देख रहा है। – Ambroos

+0

क्या आपको इसका उत्तर मिला? मैंने एक बक्षीस खोला क्योंकि मुझे बिल्कुल वही समस्या है। – dccarmo

उत्तर

2

यह वेबपैक ओवरहेड नहीं है। यह ओवरहेड किसी अन्य कारण से होता है। यहां प्रदर्शन वेबपैक विन्यास। वेबपैक सामग्री alert() के साथ स्रोत के लिए बंडल का निर्माण करता है जिसके परिणामस्वरूप 96kb के परिणामस्वरूप केवल 51 9 बाइट परिणाम घोषित किए जाते हैं। परियोजना सामग्री और परिणाम बंडलों (न्यूनतम किया और गैर minified) कर रहे हैं:

package.json

{ 
    "name": "app", 
    "version": "1.0.0", 
    "main": "webapp.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "build": "webpack" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "babel-preset-react": "^6.3.13", 
    "express": "^4.15.3", 
    "react": "^15.5.4", 
    "react-dom": "^15.5.4" 
    }, 
    "devDependencies": { 
    "babel-cli": "^6.24.1", 
    "babel-core": "^6.24.1", 
    "babel-loader": "^7.0.0", 
    "babel-preset-es2015": "^6.24.1", 
    "babel-preset-react": "^6.24.1", 
    "ts-loader": "^2.1.0", 
    "typescript": "^2.3.3", 
    "webpack": "^2.5.1" 
    }, 
    "description": "" 
} 

tsconfig.json

{ 
    "compilerOptions": { 
    "outDir": "./public/", 
    "sourceMap": true, 
    "noImplicitAny": true, 
    "module": "commonjs", 
    "target": "es5", 
    "jsx": "react", 
    "allowJs": true 
    } 
} 

alert.ts

alert(1); 

index.html

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8" /> 
     <title>Hello Workd!</title> 
    </head> 
    <body> 
     <div id="root"></div> 
     <script type="text/javascript" src="alert.js"></script> 
    </body> 
</html> 

webpack.config.js

var webpack = require('webpack'); 
var path = require('path'); 
module.exports = { 
    entry: { 
    App: './App', 
    alert: './alert.ts', 
    }, 
    output: { 
    path: path.join(__dirname, './public'), 
    filename: '[name].js' 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /\.js$/, 
     exclude: /node_modules/, 
     loader: 'babel-loader', 
     query: { 
      presets: ['es2015', 'react'] 
     } 
     }, 
     { 
     test: /\.tsx?$/, 
     loader: 'ts-loader', 
     exclude: /node_modules/, 
     } 
    ] 
    }, 
    plugins: [ 
    new webpack.optimize.UglifyJsPlugin() 
    ] 
} 

alert.js - mininied से जेनरेट

!function(n){function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var t={};r.m=n,r.c=t,r.i=function(n){return n},r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:e})},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},r.p="",r(r.s=182)}({182:function(n,r){alert(1)}}); 

alert.js - उत्पन्न गैर मिनट

/******/ (function(modules) { // webpackBootstrap 
/******/ // The module cache 
/******/ var installedModules = {}; 
/******/ 
/******/ // 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] = { 
/******/   i: moduleId, 
/******/   l: false, 
/******/   exports: {} 
/******/  }; 
/******/ 
/******/  // Execute the module function 
/******/  modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 
/******/ 
/******/  // Flag the module as loaded 
/******/  module.l = true; 
/******/ 
/******/  // Return the exports of the module 
/******/  return module.exports; 
/******/ } 
/******/ 
/******/ 
/******/ // expose the modules object (__webpack_modules__) 
/******/ __webpack_require__.m = modules; 
/******/ 
/******/ // expose the module cache 
/******/ __webpack_require__.c = installedModules; 
/******/ 
/******/ // identity function for calling harmony imports with the correct context 
/******/ __webpack_require__.i = function(value) { return value; }; 
/******/ 
/******/ // define getter function for harmony exports 
/******/ __webpack_require__.d = function(exports, name, getter) { 
/******/  if(!__webpack_require__.o(exports, name)) { 
/******/   Object.defineProperty(exports, name, { 
/******/    configurable: false, 
/******/    enumerable: true, 
/******/    get: getter 
/******/   }); 
/******/  } 
/******/ }; 
/******/ 
/******/ // getDefaultExport function for compatibility with non-harmony modules 
/******/ __webpack_require__.n = function(module) { 
/******/  var getter = module && module.__esModule ? 
/******/   function getDefault() { return module['default']; } : 
/******/   function getModuleExports() { return module; }; 
/******/  __webpack_require__.d(getter, 'a', getter); 
/******/  return getter; 
/******/ }; 
/******/ 
/******/ // Object.prototype.hasOwnProperty.call 
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 
/******/ 
/******/ // __webpack_public_path__ 
/******/ __webpack_require__.p = ""; 
/******/ 
/******/ // Load entry module and return exports 
/******/ return __webpack_require__(__webpack_require__.s = 182); 
/******/ }) 
/************************************************************************/ 
/******/ ({ 

/***/ 182: 
/***/ (function(module, exports) { 

alert(1); 


/***/ }) 

/******/ });