Giter Club home page Giter Club logo

Comments (2)

cheungseol avatar cheungseol commented on July 20, 2024

在html 模板中自动引入打包文件

通常使用 webpack 打包的项目,会使用 HtmlWebpackPlugin 在模板中自动插入 script 标签,引入打包文件(script 脚本引入的路径是 output 中的 publicPath)。

new HtmlWebpackPlugin({
            title: 'test',
            template: '!!raw-loader!' + '/template.html',  // 模板文件路径
            filename: './server/views/index.ejs',           // 生成的文件路径,供 node serve 
            inject: 'body', 
            hash: false,
            minify: {
                removeComments: false,
                collapseWhitespace: false,
            },
}),

from cheungseol.github.io.

cheungseol avatar cheungseol commented on July 20, 2024

在html 模板中自动引入 dll 打包文件

有时候,会将 dll 文件放在 cdn 上,并给 dll 包名以hash值区分。为了在 html 模板文件中自动引入 dll 包文件,需要 AddAssetHtmlPlugin。

webpack.config.js

        new AddAssetHtmlPlugin({
            includeSourcemap: false, 
            filepath: path.resolve(__dirname, 'server/static/js/lib.*.js'),   // * 符号匹配 dll 哈希名称
        }),

webpack 编译时提示 ”...dll.js.map not found“, 需要配置插件选项:includeSourcemap: false,

dll.config.js

module.exports = {
    entry: {
        lib: ['react', 'react-dom', 'react-router-dom', 'react-router-redux', 'react-router-config', 'react-redux'],
    },
    output: {
        path: path.resolve(__dirname, 'server/public/js'),
        filename: '[name].[hash:8].js',   // 生成的 dll 文件以hash命名
        library: '[name]',
    },
    plugins: [
        new webpack.DllPlugin({
            path: './manifest.json',
            name: '[name]',
            context: path.resolve(__dirname, 'client/'),
        }),
    ],
    cache: true,
};

参考

add-asset-html-webpack-plugin

教你如何玩转webpack.DllPlugin

devtool: 'eval' causes vendor.dll.js.map error #13

from cheungseol.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.