小编Mar*_*cer的帖子

webpack html(ejs)包含其他模板

所以这是我的webpack配置:

import path from 'path';

var HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    entry: {
        index: './dev/index.js'
    },
    output: {
        path: path.join(__dirname, 'dist'),
        // publicPath: 'http://localhost:3000/',
        filename: 'bundle.js',
        chunkFilename: '[id].bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: path.resolve(__dirname, "node_modules"),
                loader: 'babel-loader'
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            hash: true,
            template: 'ejs!./dev/index.ejs',
            inject: 'body'
        })
    ]

};
Run Code Online (Sandbox Code Playgroud)

我的index.ejs档案:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <%- include html/one/1.ejs %>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

我的文件夹结构:

dev/
  /assets …
Run Code Online (Sandbox Code Playgroud)

template-engine ejs webpack webpack-dev-server html-webpack-plugin

5
推荐指数
2
解决办法
6532
查看次数

Webpack-dev-server 不会在更改时构建文件

所以我有以下 webpack 配置:

import path from 'path';

module.exports = {
    entry: {
    index: './dev/index.js'
    },
    output: {
        path: path.join(__dirname, 'dist'),
        publicPath: './dist/',
        filename: 'bundle.js',
        chunkFilename: '[id].bundle.js'
    },
    module:{
        loader:{
            test: /\.js$/,
            exclude:path.resolve(__dirname, "node_modules"),
            loader: 'js'
        }
    }

};
Run Code Online (Sandbox Code Playgroud)

问题是,当我做文件时,每次更改都会webpack --watch在/dist/文件夹中构建。然而,当我运行这些webpack-dev-server文件时,甚至都没有构建。这是为什么?

请帮忙。

javascript webpack webpack-dev-server webpack-style-loader

1
推荐指数
1
解决办法
1356
查看次数