Webpack

Is this possible to configure publicPath in vue-cli dynamically in runtime?

泄露秘密 提交于 2021-02-07 09:45:43
问题 Is this possible to change dynamically publicPath for vue application (in vue.config)? This means that I want to set public path be dynamically depends on real url(some domain), e.g. i want to make only one build, but use it for staging and prod env (and use different cdn-s for assets in different countries, etc). I find that webpack_public_path aims at setting at runtime the public path. But how can I use webpack_public_path with vueJS(vue-cli)? webpack_public_path - didn't work for me.

webpack dev server is not creating the bundle file

旧时模样 提交于 2021-02-07 09:42:27
问题 I'm new to webpack and I'm using webpack dev server for HOT reload.My config looks like this: new WebpackDevServer(webpack(config), { publicPath: "./public/dist/bundle.js", hot: true, historyApiFallback: true, proxy: { '*': { target: 'http://localhost:3000', secure: false } } }).listen(8080, 'localhost', function (err, result) { if (err) { return console.log(err); } console.log('Listening at http://localhost:8080/'); }); and when I start the webpack dev server, I expect it to bundle the js at

webpack dev server is not creating the bundle file

眉间皱痕 提交于 2021-02-07 09:40:58
问题 I'm new to webpack and I'm using webpack dev server for HOT reload.My config looks like this: new WebpackDevServer(webpack(config), { publicPath: "./public/dist/bundle.js", hot: true, historyApiFallback: true, proxy: { '*': { target: 'http://localhost:3000', secure: false } } }).listen(8080, 'localhost', function (err, result) { if (err) { return console.log(err); } console.log('Listening at http://localhost:8080/'); }); and when I start the webpack dev server, I expect it to bundle the js at

Webpack 构建优化总结

ⅰ亾dé卋堺 提交于 2021-02-07 09:33:25
初级分析:使用webpack内置的stats stats:构建统计信息 package.json中使用stats "scripts": { "build:stats":"webpack --env production --json > stats.json" } 复制代码 指定输出的json对象,输出一个json文件 Node.js 中使用 const webpack = require('webpack') const config = require('./webpack.config.js')('production') webacpk(config, (err, stats) => { if(err) { return console.error(err); } if(stats.hasErrors()) { return console.log(stats.toString("errors-only")) } console.log(stats); }) 复制代码 缺点:颗粒度太粗,看不出问题所在。 速度分析:使用speed-measure-webpack-plugin const SpeedMeasureWebpackPlugin = require('speed-measure-webpack-plugin') const smp = new

How to use npm installed package in laravel application?

 ̄綄美尐妖づ 提交于 2021-02-07 09:32:42
问题 I want to use select2 package in my laravel 5 application. I installed it using npm install select2 and also ran npm run dev . It appears in my node_modules folder. But how do I actually refer to the files - js and scss of select2 package in my app.blade.php ? 回答1: Run npm run watch , because keeps track of all changes in .js . In app.js add require('select2/dist/js/select2'); In app.blade.php example: <div> <select class="js-select2 css-select2-50"> <option>1</option> </select> </div> 来源:

How to use npm installed package in laravel application?

跟風遠走 提交于 2021-02-07 09:31:06
问题 I want to use select2 package in my laravel 5 application. I installed it using npm install select2 and also ran npm run dev . It appears in my node_modules folder. But how do I actually refer to the files - js and scss of select2 package in my app.blade.php ? 回答1: Run npm run watch , because keeps track of all changes in .js . In app.js add require('select2/dist/js/select2'); In app.blade.php example: <div> <select class="js-select2 css-select2-50"> <option>1</option> </select> </div> 来源:

Webpack import from files that use module.exports

蓝咒 提交于 2021-02-07 09:28:36
问题 I have React app and a file where I want to store things related to api. const proxy = require('http-proxy-middleware'); const path = require('path'); //..... const targetApi = (objectWithUrlEntries) => { Object.keys(objectWithUrlEntries).forEach((key) => { objectWithUrlEntries[key] = path.join('/api/', objectWithUrlEntries[key]); }); }; module.exports.proxyExpressCalls = proxyExpressCalls; module.exports.devServerProxyConfig = devServerProxyConfig; module.exports.targetApi = targetApi; Some

Overlapping CSS in React, Webpack application

谁都会走 提交于 2021-02-07 08:48:05
问题 I have created an application using webpack and reactjs. So far I have created 2 pages. I have defined CSS styling for both the pages. But when I load page 2 after loading page 1, the styles from page 1 are interfering with those of page 2. For example Page 1 require('style1.css'); var Page1 = React.createClass({ render: function(){ return( <div> <h1>This is Page1</h1> <span> hello from page1</span></div> ) } }); module.exports = Page1; style1.css span { color : red } Page 2 require('style2

Overlapping CSS in React, Webpack application

纵饮孤独 提交于 2021-02-07 08:47:31
问题 I have created an application using webpack and reactjs. So far I have created 2 pages. I have defined CSS styling for both the pages. But when I load page 2 after loading page 1, the styles from page 1 are interfering with those of page 2. For example Page 1 require('style1.css'); var Page1 = React.createClass({ render: function(){ return( <div> <h1>This is Page1</h1> <span> hello from page1</span></div> ) } }); module.exports = Page1; style1.css span { color : red } Page 2 require('style2

How do I dynamically import images in React?

こ雲淡風輕ζ 提交于 2021-02-07 08:01:48
问题 Have seen a couple of answers online but there are no clear explanations and the solutions don't work. So this is what I am trying to do: I have a folder of MANY images (thousands) - currently it is saved under src/assets/images folder Given a list of images for example as input, I want to render these images dynamically . And not import all because it would be impossible given the insane number of images This is my current way of implementing it ( which does not work ): // for example const