25

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
  • Similar question with different answers here Commented Mar 20, 2019 at 21:16

1 Answer 1

29

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';
Sign up to request clarification or add additional context in comments.

4 Comments

Thx there is no info on how to do this. in my case i had to import sha512 with this: import sha512 from './../../../../../../node_modules/js-sha512/src/sha512'
Just wanted to mention this did work: import 'nodePackage/subFolder/my-js-file.js';
Which file should this import be included in?
Its quite a long time I used it. Afaik ''./entry.js" or any js file imported from "/entry"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.