Angularjs 生产中的网页包

Angularjs 生产中的网页包,angularjs,caching,webpack,production,Angularjs,Caching,Webpack,Production,我是一个正在使用webpack angular的项目,已经成功地生成了包并将其注入index.html文件 但在浏览器中,我可以在“源”选项卡中看到“添加网页包”文件夹,其中包含旧代码,除非清除浏览器缓存,否则我无法找到最新的代码。但是,有生成的包和样式,但我的页面不接受这些文件,它们是从webpack文件夹中获取代码 我附加了我在浏览器中看到的文件夹结构,你可以看到代码呈现的构建文件夹,以及没有更新最新代码的网页文件夹,谢谢你的帮助, 谢谢 =========================

我是一个正在使用webpack angular的项目,已经成功地生成了包并将其注入index.html文件

但在浏览器中,我可以在“源”选项卡中看到“添加网页包”文件夹,其中包含旧代码,除非清除浏览器缓存,否则我无法找到最新的代码。但是,有生成的包和样式,但我的页面不接受这些文件,它们是从webpack文件夹中获取代码

我附加了我在浏览器中看到的文件夹结构,你可以看到代码呈现的构建文件夹,以及没有更新最新代码的网页文件夹,谢谢你的帮助, 谢谢

==================================================== Webpack.development.config.js

const webpack = require('webpack');
const path = require("path");
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
HtmlWebpackPlugin = require('html-webpack-plugin');
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const buildPath = path.resolve(__dirname,'app/build');
const mainPath = path.resolve(__dirname, 'app', 'index.js');
const config = {
    context:__dirname, 
    entry:  {
     app:[
        mainPath
      ],
    vendors: ['jquery','angular']
    },
    output:{
        path:buildPath,
        filename:"bundle.min.js",
        publicPath: "http://website.oo.com/build/" // development
    },
    devtool: 'source-map',
    resolve:{
        alias:{     
            jquery: "jquery/src/jquery"
        },
        extensions:['','.js','.css','.less','.html']
    },
    module:{
        loaders:[
            {test: /\.js$/,loader: 'babel-loader',query:{presets: ["es2015"],compact: false},exclude: '/node_modules/'},  
            {test: /\.less$/,loader:ExtractTextPlugin.extract(['css','less']) },   
            {test: /\.css$/,loader:ExtractTextPlugin.extract(['css'])},  
            {test: /\.html$/,loader: "html?config=otherHtmlLoaderConfig"},
            {test: /bootstrap\/js\//, loader:'imports?jQuery=jquery'}, 
            {test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader:'url-loader',query:{limit:100000}},
            {test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff"},
            {test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
            {test: /[\/\\]node_modules[\/\\]some-module[\/\\]index\.js$/,loader: "imports?this=>window"}   
        ]
  }, 
  plugins: [
    new webpack.ProvidePlugin({$: "jquery",jQuery: "jquery"}),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.AggressiveMergingPlugin({minSizeReduce:1,moveToParents: true}),
    new webpack.optimize.UglifyJsPlugin({compress: { warnings: false },comments:false,sourceMap:true,minimize: true}),
    new ExtractTextPlugin('style.min.css', { allChunks: true }),  
    new webpack.optimize.CommonsChunkPlugin('vendors', 'vendor.min.js'),
    new CleanWebpackPlugin(['app/build'],{verbose: true,dry: false,exclude: ['vendor.min.js'],watch:false}),
    new HtmlWebpackPlugin({
      title: 'Onepoint Global Account',
      template:path.join(__dirname,'app','index.html'),
      inject: 'body'}),
  ]
};
module.exports = config; 
======================================================== Package.json

"scripts": {
    "local": "webpack-dev-server --content-base app",
    "server": "node server",
    "build": "set NODE_ENV=production && webpack -d --watch -p --config  webpack.development.config.js"
  }

我使用命令“npm run build”启动项目。

解决您的两点:

  • /build
    位于URL中,因为这一行:

    publicPath: "http://website.oo.com/build/" // development
    
    您的
    buildPath
    是您可以承载站点的目录

  • 您是否有
    webpack.prod.config.js
    ?只有一个网页包配置文件是可以的,但请注意,您正在使用开发配置运行生产(
    set NODE_ENV=production
    ,和
    -p
    )。如果要取消浏览器缓存,可以在输出文件中指定哈希:

    output: {
      ...
      filename:"bundle.[hash].min.js",
    },
    

  • 如果这是您在运行webpack dev serevr时看到的文件夹结构,那么就可以了。这就是您想要看到的内容-网页包向您显示结果包(build/)以及源代码(webpack://..)因此,您可以轻松地调试应用程序。请详细解释你对什么不满意。给你的网页配置和运行你的应用程序的命令也会有帮助。1.是URL,我必须添加“build”-“www.website.com/build/#/login”来呈现更新的文件。2.即使在这之后,你在图片中看到的Webpack文件夹,源代码没有最新的html或js更改(除非我清除浏览器缓存-ctrl+shift+delete),我在生产模式下使用Webpack,而不是Webpack dev server@PetrAveryanov已经用配置文件和我用来运行项目的命令更新了我的问题。@PetrAveryanov在这方面有什么帮助吗,非常感谢?谢谢