How to include external file with webpack

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

Is it possible to include external file with webpack (outside the context) and make the file included in built output bundle.js?

consider this setup where "sub-app" is context for webpack:

  • /sub-app/entry.js
  • /bower-components/zepto/zepto.js

And webpack config with broccoli:

var webpackify = require('broccoli-webpack'); var path = require('path'); var webpack = require("webpack");  var bundler = webpackify(path.resolve('sub-app'), {     entry: './entry',     output: {filename: './bundle.js'},     devtool: 'eval',      module: {       loaders: [         {test: /\.js$/, loader: 'babel-loader'},         {test: /\.hbs$/, loader: "handlebars-loader"}       ]     },     plugins: [       new webpack.optimize.DedupePlugin(),       new webpack.optimize.UglifyJsPlugin()     ] }); 

I would like to include zepto.js in output bundle.js. But I need to preserve bower_components outside the sub-app.

回答1:

Ok found answer myself. No special adjustments are necessary. Only include external file in code with relative path:

In my case:

import zepto from './../bower_components/zepto/zepto.js'; 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!