html-webpack-plugin

html-webpack-plugin not inject js file into index.html when using webpack-dev-server

徘徊边缘 提交于 2019-12-02 21:14:38
Here is my webpack config : var path = require('path'); var webpack = require('webpack') var HtmlWebpackPlugin = require('html-webpack-plugin') var fs = require('fs'),buildPath='./dist/'; var folder_exists = fs.existsSync(buildPath); if(folder_exists == true) { require('shelljs/global') rm('-rf', 'dist') }; module.exports = { entry: './src/main', output: { path: path.join(__dirname, './dist'), filename: '[name].js', publicPath: '/dist/' }, devServer: { historyApiFallback: true, hot: false, inline: true, grogress: true, }, // "vue-hot-reload-api": "^1.2.2", module: { loaders: [ { test: /\.vue$/

Add script file to HTML in webpack based on environment

末鹿安然 提交于 2019-12-01 14:17:32
I'm trying to add a specific js file to my index.html when bundling my application for production. My webpack.common.js has the following files that get injected into the html: entry: { 'polyfills': './src/polyfills.ts', 'vendor': './src/vendor.ts', 'app': './src/main.ts' }, And in the plugins section I have: new webpack.optimize.CommonsChunkPlugin({ name: ['app', 'vendor', 'polyfills'] }), For my webpack.prod.js I have the following output: output: { path: helpers.root('dist'), publicPath: '/', filename: '[name].[chunkhash].js', chunkFilename: '[id].chunk.js' }, And everything works just fine

How can I use multiple entries in Webpack alongside multiple HTML files in HtmlWebpackPlugin?

五迷三道 提交于 2019-12-01 12:40:11
We'd like to have two outputs from Webpack - our entire app with all of its dependencies, and a single different page with only one dependency (that isn't shared by the main app). It seems the way to do this is to leverage the entry property of a Webpack config. However, that's not enough, as we also use HtmlWebpackPlugin to output our HTML file with the build.js that Webpack compiled dynamically added (as well as compiled LESS, etc). According to the HtmlWebpackPlugin docs: If you have multiple Webpack entry points, they will all be included with script tags in the generated HTML. That won't

How can I use multiple entries in Webpack alongside multiple HTML files in HtmlWebpackPlugin?

℡╲_俬逩灬. 提交于 2019-12-01 10:39:24
问题 We'd like to have two outputs from Webpack - our entire app with all of its dependencies, and a single different page with only one dependency (that isn't shared by the main app). It seems the way to do this is to leverage the entry property of a Webpack config. However, that's not enough, as we also use HtmlWebpackPlugin to output our HTML file with the build.js that Webpack compiled dynamically added (as well as compiled LESS, etc). According to the HtmlWebpackPlugin docs: If you have

import CSS and JS files using Webpack

岁酱吖の 提交于 2019-11-30 12:22:10
I have a directory structure like this: and inside node_modules: >node_modules >./bin >webpack.config.js >bootstrap >bootstrap.css >bootstrap.js I need to generate separate CSS and JS bundles like this: custom-styles.css, custom-js.js, style-libs.css, js-libs.js where style-libs and js-libs should contain syles and js files of all libraries like bootstrap and jQuery. Here's what I have done so far: webpack.config.js: const path = require('path'); const basedir = path.join(__dirname, '../../client'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const stylesPath = path.join(_

How to use Webpack 4 SplitChunksPlugin with HtmlWebpackPlugin for Multiple Page Application?

寵の児 提交于 2019-11-30 10:58:31
问题 I'm trying to utilize the SplitChunksPlugin to produce separate bundles per each page/template in a MPA. When I use the HtmlWebpackPlugin, I get an html file for each page with a script tag pointing to the correct bundle. That is great! However, the trouble I'm having is with my vendor files. I want separate html files to point to only the vendor bundles they need. I can't get each separate html file to point to the correct vendor bundles when the SplitChunksPlugin creates multiple vendor

Nested React router 4 routes not working on Webpack 3

白昼怎懂夜的黑 提交于 2019-11-28 08:23:01
问题 As the tittle suggest i can't get routes like <Route path="/events/:id" component={EventDetailRoute} /> to work, and as i've read seems to be that the bundle in the index.html must be absolute, however i'm using the HtmlWebpackPlugin so the bundle gets injected as a relative path. I've tried to set my output config for webpack as follows: output: { path: path.resolve('dist'), filename: 'index_bundle.js', publicPath: '/' }, But that doesn't work neither. If i try this route: http://localhost

How to use Webpack with Google Maps API?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:08:39
问题 I am using Webpack + html-webpack-plugin to build all my static files. The thing is, when I am using it with Google Maps API, it's not working. I have this code: var map; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat: -34.397, lng: 150.644}, zoom: 6 }); // the other code, irrelevant } And a HTML file: <!doctype html> <html> <head> </head> <body> <div id="map"></div> <script async="async" defer="defer" src="https://maps.googleapis.com/maps/api/js