无法解决如何强制 WebPack 3.6 构建最终dist。
只是输出文件夹是空的。使用给定的配置,应用程序在浏览器内存中构建并运行,但是dist文件夹是空的,现在有任何物理文件。
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const StyleExtHtmlWebpackPlugin = require('style-ext-html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const autoprefixer = require('autoprefixer');
const staticSourcePath = path.join(__dirname, 'static');
const sourcePath = path.join(__dirname);
const buildPath = path.join(__dirname, 'dist');
module.exports = {
devtool: 'cheap-module-source-map',
entry: {
/*base: path.resolve(staticSourcePath, 'src/sass/base.scss'),*/
app: path.resolve(sourcePath, 'index.js')
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[chunkhash].js', …Run Code Online (Sandbox Code Playgroud) 我正在使用React Router V4,并且已经有了该路由器的配置:
<Router history={customHistory}>
<Switch>
<Route exact path={`/:lng?`} component={Page} />
<Route path={`/:lng?/firstUrl`} component={Page}/>
<Route path={`/:lng?/secondUrl`} component={Page}/>
<Route component={NoMatch} />
</Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)
该lng是可选的语言参数应符合像模式en,de或不存在。例如,应用利用以下路线:
www.website.com/en
www.website.com/en/
www.website.com/ - will load default lang
www.website.com - will load default lang
www.website.com/de
www.website.com/de/
Run Code Online (Sandbox Code Playgroud)
另外,我还有其他组件,在其中定义了函数的路由:
<ModalRoute component={SomeURL} path={`/:lng?/SomeURL`} parentPath={`/${lang}/`} />
<ModalRoute component={SomeURL2} path={`/:lng?/SomeURL2`} parentPath={`/${lang}/`} />
Run Code Online (Sandbox Code Playgroud)
因此,作为结果,我希望实现的是,仅接受允许的语言代码(和空参数),而不会接受-将被重定向到NoMatch组件。
可能吗?如何实现?
例子非常感谢
我有CMS,这使得以这样的方式,我不能添加任何额外的标记id,class或events到元素。
这样,我必须以编程方式添加它们。任务很简单:
1)。通过类名称查找元素并添加到其后继者(img)id名称
2)。onClick给它添加属性
3)。执行脚本onClick(应交换图像和href名称(最多3张图像))
这是一个标记:
<div class="single-image text-center to_change_inner">
<div class="content">
<div class="single-image-container">
<img class="img-responsive" src="https://picsum.photos/200/300">
</div>
</div>
</div>
<div>
<a id="btn-1559300726188">Click</a>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个JQuery:
jQuery(function($) {
element1 = $('.to_change_inner').children('img'); //find() also doesn't work
element1.id="imgClickAndChange";
if (element1.addEventListener) {
element1.addEventListener("click", changeImage, false);
} else {
if (element1.attachEvent) {
element1.attachEvent("click", changeImage);
}
}
});
function changeImage() {
if (document.getElementById("imgClickAndChange").src == "https://picsum.photos/200/300")
{
document.getElementById("imgClickAndChange").src = …Run Code Online (Sandbox Code Playgroud)