webpack-externals

Externals defined in webpack.config still getting error module not found

不问归期 提交于 2019-12-22 09:58:02
问题 I have defined externals in webpack.config for material-ui module.exports = [{ entry: ... output:... externals: { react: { commonjs: "react", commonjs2: "react" }, "material-ui": { commonjs: "material-ui", commonjs2: "material-ui" } }, module: ... }]; Still its giving error like- Cannot resolve module 'material-ui/IconButton'...... In my entry js file, I have import React, {Component} from "react"; import IconButton from "material-ui/IconButton"; ..... ..... 回答1: Ok I solved it. External

Externals defined in webpack.config still getting error module not found

拜拜、爱过 提交于 2019-12-05 20:15:49
I have defined externals in webpack.config for material-ui module.exports = [{ entry: ... output:... externals: { react: { commonjs: "react", commonjs2: "react" }, "material-ui": { commonjs: "material-ui", commonjs2: "material-ui" } }, module: ... }]; Still its giving error like- Cannot resolve module 'material-ui/IconButton'...... In my entry js file, I have import React, {Component} from "react"; import IconButton from "material-ui/IconButton"; ..... ..... Ok I solved it. External expects complete path. So either, import {IconButton} from "material-ui" or externals: { "material-ui/IconButton

How to use a library from a CDN in a Webpack project in production

本小妞迷上赌 提交于 2019-11-27 12:20:47
I'd like to use react.min.js from a CDN in production (e.g. https://unpkg.com/react@15.3.1/dist/react.min.js ) What is the best way to get Webpack to transform my import React from 'react' statements into const React = window.React instead of building node_modules/react into the bundle? I've been doing it with resolve.alias like this: In index.html : <head> <script type="text/javascript" src="https://unpkg.com/react@15.3.1/dist/react.min.js"></script> <script type="text/javascript" src="/assets/bundle.js"></script> </head> In webpack.prod.config.js : alias: { react$: './getWindowReact', },

How to use a library from a CDN in a Webpack project in production

为君一笑 提交于 2019-11-26 13:05:03
问题 I\'d like to use react.min.js from a CDN in production (e.g. https://unpkg.com/react@15.3.1/dist/react.min.js) What is the best way to get Webpack to transform my import React from \'react\' statements into const React = window.React instead of building node_modules/react into the bundle? I\'ve been doing it with resolve.alias like this: In index.html : <head> <script type=\"text/javascript\" src=\"https://unpkg.com/react@15.3.1/dist/react.min.js\"></script> <script type=\"text/javascript\"