npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coco-platform/webpack-plugin-inject-external

v1.1.0

Published

Inject externals resource automatic.

Downloads

15

Readme

webpack-plugin-inject-external

Build Status Coverage Status Greenkeeper badge Package Dependency Package DevDependency

Usage

# npm
npm install @coco-platform/webpack-plugin-inject-external --only=dev;
# yarn
yarn add @coco-platform/webpack-plugin-inject-external --dev;

Options

/**
 * @typedef {object} Options
 *
 * @property {string} env - development, production or other environment name
 * @property {string} definition - YAML file path, whose contents describe external resources
 */

Configurations

webpack-plugin-inject-external use yaml config file, single external module define like below:

interface CompoundLinkage {
  url: string;
  integrity: string; // required property within compound mode
}

type Linkage = string | string[] | CompoundLinkage | Array<CompoundLinkage>;

// single external module
type Module = {
  name: string;
  linkage: Linkage;
};

when external module reference the same resource within different environment:

library:
  - name: 'web-animations-js'
    linkage: 'https://unpkg.com/[email protected]/web-animations.min.js'

when external module reference different resource within different environment:

environment:
  development:
    - name: 'react'
      linkage: 'https://cdn.bootcss.com/react/16.3.2/umd/react.development.js'
    - name: 'moment'
      linkage:
        - 'https://cdn.bootcss.com/moment.js/2.22.1/moment.js'
        - 'https://cdn.bootcss.com/moment.js/2.22.1/locale/zh-cn.js'
  production:
    - name: 'react'
      linkage:
        url: 'https://cdn.bootcss.com/react/16.3.2/umd/react.production.min.js'
        integrity: 'sha384-xH6t0qiGSnjsUirN+xJjNhsfepiFFyK/wHMjrqPu6OoxN8uDO454QqZx3Wcos7en'

Usage

Then config the webpack:

const configuration = {
  entry: path.resolve(__dirname, '__fixture__', 'index.js'),
  output: {
    path: path.resolve(process.cwd(), 'dist'),
    filename: '[name].js',
    publicPath: '/',
  },
  externals: {
    moment: 'moment',
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, '__fixture__', 'index.html'),
      inject: 'body',
    }),
    new InjectExternalPlugin({
      env: 'production',
      definition: path.resolve(
        __dirname,
        '__fixture__',
        'bootcdn.externals.yml'
      ),
    }),
  ],
};

Finally output:

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Webpack Plugin</title>
  </head>
  <body>
    <script
      type="text/javascript"
      src="https://cdn.bootcss.com/moment.js/2.22.1/moment.min.js"
      crossorigin="anonymous"
      integrity="sha384-fYxN7HsDOBRo1wT/NSZ0LkoNlcXvpDpFy6WzB42LxuKAX7sBwgo7vuins+E1HCaw"
    ></script
    ><script
      type="text/javascript"
      src="https://cdn.bootcss.com/moment.js/2.22.1/locale/zh-cn.js"
      crossorigin="anonymous"
      integrity="sha384-XjUTsP+pYBX4Kwg40gPvhWcRGKZh9gUpDForgg5bwsnyNU+VabKhRX6XkyM6fLk4"
    ></script
    ><script type="text/javascript" src="/main.js"></script>
  </body>
</html>

License

MIT