如何在webpack中包含外部文件 [英] How to include external file with webpack

查看:157
本文介绍了如何在webpack中包含外部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在webpack中包含外部文件(在上下文之外)并将文件包含在内置输出bundle.js中?

考虑这个设置,其中sub-app是webpack的上下文:

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


  • /sub-app/entry.js

  • /bower-components/zepto/zepto.js

带有西兰花的webpack配置:

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()
    ]
});

我想在输出bundle.js中包含zepto.js。但是我需要在子应用程序之外保留bower_components。

推荐答案

好的,找到自己回答。无需特别调整。仅包含具有相对路径的代码中的外部文件:

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

在我的情况下:

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

这篇关于如何在webpack中包含外部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆