基于webpack.config.js和babel.config.js及package.json构建项目的demo

webpack.config.js的内容如下

const HtmlWebpackPlugin = require(‘html-webpack-plugin‘);
const Webpack = require("webpack");
const ConcatPlugin = require(‘webpack-concat-plugin‘);
const CopyPlugin = require(‘copy-webpack-plugin‘);
const Path = require(‘path‘);
const ImageInlineSizeLimit = 10000;

module.exports = (env, argv) => {
    const isDev = ‘development‘ === argv[‘mode‘];
    return {
        entry: {
            init_global: ‘./src/global.js‘,
            app: ‘./src/app.js‘
        },
        module: {
            rules: [{
                    test: [/\.js$/, /\.jsx$/],
                    exclude: /node_modules/,
                    loader: ‘babel-loader‘
                }, {
                    test: /\.css|scss$/, //*.global.css->不开启css-loader modules
                    loader: ‘style-loader!css-loader!sass-loader‘
                },
                /*{
                    test: /^(?!.*\.global).*\.css/, //*.global.css->不开启css-loader modules
                    loader: ‘style-loader!css-loader?modules‘
                }, {
                    test: /^(.*\.global).*\.css/, //*.css->开启css-loader modules
                    loader: ‘style-loader!css-loader‘
                },*/
                {
                    test: /\.xml$/,
                    loader: ‘raw-loader‘
                }, {
                    test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
                    loader: ‘url-loader‘,
                    options: {
                        limit: ImageInlineSizeLimit,
                        name: ‘static/media/[name].[hash:8].[ext]‘,
                    },
                }
            ]
        },
        resolve: {
            extensions: [‘.js‘, ‘.jsx‘, ‘.css‘],
        },
        devServer: {
            contentBase: Path.join(__dirname, ‘public‘),
        },
        devtool: "eval-source-map",
        plugins: [new HtmlWebpackPlugin({
            filename: ‘index.html‘,
            //按顺序引入
            inject: false,
            template: ‘src/assets/index.html‘
        }), new ConcatPlugin({
            uglify: !isDev,
            sourceMap: false,
            injectType: "none",
            name: ‘editor‘,
            fileName: ‘[name].[hash:8].js‘,
            filesToConcat: [
                ‘mxgraph/javascript/mxClient.js‘,
                Path.resolve(__dirname, ‘src/thirdparty/editor/sanitizer/sanitizer.min.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Editor.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/EditorUi.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Graph.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Actions.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Dialogs.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Format.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Menus.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Shapes.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Sidebar.js‘),
                Path.resolve(__dirname, ‘src/thirdparty/editor/js/Toolbar.js‘),
            ]
        }), new CopyPlugin([{
            from: Path.resolve(__dirname, ‘public/static‘),
            to: "static",
            toType: ‘dir‘,
        }])]
    }
};

babel.config.js的内容如下:

module.exports = {
    presets: [
        [‘@babel/preset-env‘, {
            targets: {
                node: ‘current‘,
            },
        }],
        ‘@babel/preset-react‘
    ],
    plugins: [
        "@babel/plugin-proposal-class-properties"
    ]
};

package.json的依赖如下:

{
    "name": "design-studio",
    "version": "1.0.0",
    "scripts": {
        "start": "webpack-dev-server --mode development",
        "build": "webpack --mode production"
    },
    "devDependencies": {
        "@babel/cli": "7.6.0",
        "@babel/core": "7.6.0",
        "@babel/plugin-proposal-class-properties": "7.5.5",
        "@babel/preset-env": "7.6.0",
        "@babel/preset-react": "7.0.0",
        "babel-core": "6.26.3",
        "babel-loader": "8.0.6",
        "babel-plugin-transform-runtime": "6.23.0",
        "babel-preset-env": "1.7.0",
        "babel-preset-react": "6.24.1",
        "babel-preset-stage-0": "6.24.1",
        "copy-webpack-plugin": "5.0.4",
        "css-loader": "3.2.0",
        "file-loader": "4.2.0",
        "html-webpack-plugin": "3.2.0",
        "raw-loader": "3.1.0",
        "sass-loader": "8.0.0",
        "style-loader": "1.0.0",
        "url-loader": "2.1.0",
        "webpack": "4.40.2",
        "webpack-cli": "3.3.9",
        "webpack-concat-plugin": "3.0.0",
        "webpack-dev-server": "3.8.1",
        "node-sass": "^4.13.0"
    },
    "dependencies": {
        "axios": "0.19.0",
        "bootstrap": "4.3.1",
        "mxgraph": "4.0.4",
        "react": "16.10.1",
        "react-dom": "16.10.1",
        "react-jsonschema-form": "1.8.0"
    }
}

原文地址:https://www.cnblogs.com/jimaww/p/12003151.html

时间: 2024-11-05 16:42:16

基于webpack.config.js和babel.config.js及package.json构建项目的demo的相关文章

【Node.js学习笔记七】使用package.json

package.json是什么? package.json是定义了一个模块,包括其依赖关系的一个简单的JSON文本文件. 所有Node的模块必须在其根目录下包含一个package.json文件. 以下是一个包含名称.版本.描述和依赖的package.json文件的例子: 1 { 2 "name": "my_module", 3 "version": "0.1.0", 4 "description": &qu

webpack.config.js====配置babel

参考:https://www.jianshu.com/p/9808f550c6a91. 安装依赖babel-loader: 负责 es6 语法转化babel-preset-env: 包含 es6.7 等版本的语法转化规则babel-polyfill: es6 内置方法和函数转化垫片babel-plugin-transform-runtime: 避免 polyfill 污染全局变量 cnpm install --save-dev babel-core babel-loader babel-plug

vue-cli的webpack模版,相关配置文件dev-server.js与webpack.config.js配置解析

1.下载vue-cli [html] view plain copy npm install vue-cli -g vue-cli的使用与详细介绍,可以到github上获取https://github.com/vuejs/vue-cli 2.安装webpack项目模版 [html] view plain copy vue init <template-name> <project-name> 比如: [html] view plain copy vue init webpack m

基于webpack和vue.js搭建开发环境

前言 在对着产品高举中指怒发心中之愤后,真正能够解决问题的是自身上的改变,有句话说的好:你虽然改变不了全世界,但是你有机会改变你自己.秉承着“不听老人言,吃亏在眼前”的优良作风,我还是决定玩火自焚. 问题所在 之前的项目总结为以下内容: 1.AMD模块规范开发,使用requirejs实现,使用rjs打包,最终导致的结果是,输出的项目臃肿,肿的就像一坨狗不理……不忍直视2.使用gulp进行打包,这一点貌似没有可吐槽的地方,毕竟都是被grunt折磨过来的……3.数据的渲染使用模板引擎,这就意味着你要

基于webpack的Vue.js开发环境快速搭建

1. 安装node node下载地址 2. 安装淘宝 NPM 镜像命令地址 3. 安装vue # 全局安装 vue-cli cnpm install -g vue-cli 4. 创建一个基于 "webpack" 模板的新项目 # 创建一个项目文件夹,在文件夹下shift + 右键,选择在此处打开cmd vue init webpack 5. 安装依赖 # 安装依赖 cnpm install #安装完毕后,在项目路径下多出了依赖包. 6. 运行项目 #运行项目 运行成功,默认8080 端

基于webpack和vue.js搭建的H5端框架(其实主要用于Hybrid开发H5端框架,但是依然能够作为纯web端使用)

人类的发展得益于对追求不断的提升,在能活着的基础上是否要活得潇洒一点,技术的发展亦如是.在公司作为一个最最最最最最最底层的搬砖码农,经历了两个版本的铸(zhe)炼(mo)之后,我痛下决心今后一定要:…………..一定要和产品惺(shi)惺(bu)相(liang)惜(li). 开始之前 本文包含以下技术,文中尽量给与详细的描述,并且附上参考链接,读者可以深入学习: 1.webpack2.Vue.js3.npm4.nodejs —- 这个就不给连接了,因为上面的连接都是在你实践的过程中要去不断访问的5

从零开始配置webpack(基于webpack 4 和 babel 7版本)

webpack 核心概念: Entry: 入口 Module:模块,webpack中一切皆是模块 Chunk:代码库,一个chunk由十多个模块组合而成,用于代码合并与分割 Loader:模块转换器,用于把模块原内容按照需求转换成新内容 Plugin:扩展插件,在webpack构建流程中的特定时机注入扩展逻辑来改变构建结果或做你想要做的事情 Output: 输出结果 webpack流程: 原文链接: 点我 webpack启动后会从 Entry 里配置的 Module 开始递归解析 Entry 依

webpack入门之打包html,css,js,img(一)

webpack到底是什么,网上一大堆介绍的东西,越看越不知道说的什么,所以今天打算自己来记录一下这段时间学习webpack的成果, webpack就是打包文件用的,html,css,js,img,为什么通过他打包?说白了就是我们可以提前使用新的东西,es6现在浏览器支持的其实并不是很好,但这不是问题,你可以采用es6去写脚本, 然后通过webpack去打包成es5,vue项目里面的vue文件也是一样的,也是需要webpack打包成浏览器能够识别的文件才能正常使用,废话不多说,咱们搞起 找个磁盘,

基于 Koa平台Node.js开发的KoaHub.js获取/设置会话功能代码

koa-session2 Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel koa-session2     Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel If you are not using bab