鍍金池/ 問答/HTML/ webpack項(xiàng)目在dev模式的時(shí)候,每次更改會(huì)編譯所有文件

webpack項(xiàng)目在dev模式的時(shí)候,每次更改會(huì)編譯所有文件

  1. 項(xiàng)目是gulp + webpack的老項(xiàng)目
  2. 啟動(dòng)開發(fā)服務(wù)器,改動(dòng)代碼,保存之后會(huì)編譯所有文件,沒有更改的也會(huì)編譯,導(dǎo)致每次編譯很慢,每次需要三分鐘

webpack版本 2.7.0

配置

const webpackConfig = {
    devtool: devtool,
    entry: entry,
    output: {
        filename: "js/[name].js",
        path: path.join(process.cwd(), 'dist', 'assets'),
        publicPath: publicPath,
        chunkFilename: "js/ensure/[name]-[id]-[chunkhash].js",
        libraryTarget: 'umd'
    },
    resolve: {
        modules: [
            "node_modules",
            path.join(rootDir, "src/")
        ],
        alias: moduleConfig.alias
    },
    module: {
        //加載器配置
        loaders: [{ test: /\.css$/, use: 'happypack/loader?id=styles' },
            { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use: 'happypack/loader?id=js'
            },
            {
                test: /\.vue$/,
                loader: 'happypack/loader?id=vue',
            },
            { test: /\.(html|tpl)$/, loader: 'art-template-loader' }
        ]
    },
    plugins: [
        new HappyPack({
            id: 'js',
            cache: true,
            threadPool: HappyThreadPool,
            loaders: [{
                loader: 'babel-loader',
                options: {
                    presets: [
                        'stage-3'
                    ],
                    plugins: ['syntax-dynamic-import']
                }
            }],               
        }),
        new HappyPack({
            id: 'styles',
            cache: true,
            threadPool: HappyThreadPool,
            loaders: [{
                loader: 'style-loader!css-loader' 
            }],               
        }), 
        new HappyPack({
            id: 'tpl',
            cache: true,
            threadPool: HappyThreadPool,
            loaders: [{
                loader: 'art-template-loader' 
            }],               
        }),                  
        new HappyPack({
            id: 'vue',
            loaders: [
                {
                    loader: 'vue-loader',
                    options: {
                        loaders: {
                            less: 'vue-style-loader!css-loader!less-loader'
                        }
                    }           
                },             
            ]
        }),
        new webpack.ProvidePlugin(moduleConfig.global),
        new webpack.DefinePlugin({
            'baseEnv': JSON.stringify(envConfig.baseEnv),
        }),
        new webpack.LoaderOptionsPlugin({
            debug: true
        }),
        new HtmlWebpackPlugin({
            filename: path.join(rootDir, "dist/index.html"),
            template: path.join(rootDir, "src/modules/index.html"),
            publicPath: config.dev.publicPath,
            hash: true
        }),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.HotModuleReplacementPlugin() //熱加載
    ],
};
回答
編輯回答
陌璃

你的入口有多少個(gè)文件?

2018年6月19日 20:37
編輯回答
蝶戀花

樓主最后怎么解決的呢?我也碰到你這情況了....

2018年3月8日 18:55
編輯回答
陌上花

移除這句 libraryTarget: 'umd'

2017年12月30日 19:58