0.2.7 • Published 4 years ago

ecarx-build v0.2.7

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

开始使用

## 安装
$ npm i ecarx-build -S

## 查看版本
$ ecarx-build -v
0.0.13

## 运行项目
$ ecarx-build dev

## 打包项目
$ ecarx-build build

## 使用script运行或打包项目
修改package.json中的scripts
{
    "dev": "ecarx-build dev",
    "build": "ecarx-build build",
}
然后
npm run dev
npm run build

自定义配置

在项目目录下创建 webpackrc.js 文件 例如:

module.exports = {
    common:{
        entry: './src/main.js',
    },
    dev:{
        plugins:[

        ]
    },
    prod:{
        
    }
}
参数类型默认值说明
commonobject{}通用配置
devobject{}运行配置
prodobject{}打包配置

如何配置请查看webpack官网。

如果只需要改写dev可以这么写(省掉common和prod对象)

module.exports = {
    dev:{
        entry: './src/main.js',
    },
}

常用自定义配置

module.exports = {
    common:{
        entry: './src/main.js',
        /*
        修改入口文件名,比如你的项目入口是./src/main.js,打包工具默认配置是
        index.js,默认就找不到入口,所以需要自定义修改
        */
        resolve:{
            alias: {
                components: path.resolve(__dirname, 'src/components/'),
                assets: path.resolve(__dirname, 'src/assets/'),
                public: path.resolve(__dirname, 'public'),
                configs: path.resolve(__dirname, 'src/common/configs'),
                layouts: path.resolve(__dirname, 'src/layouts/'),
                utils: path.resolve(__dirname, 'src/utils'),
                common: path.resolve(__dirname, 'src/common'),
                services: path.resolve(__dirname, 'src/services'),
            },
        },
        
        /*
            alias设置路径别名,例如在项目路径下的src/components/header.js
            在src/pages/page1.js中引用header组件时,配置
            components: path.resolve(__dirname, 'src/components/')了之后
            可以直接import header from 'components/header.js',
            不配置别名时则只能import header from '../../components/header',
            在module.exports前引入const path = require('path')
        */
        module: {
            rules:[
                'sass-loader',//增加支持sass的loader,默认没有支持sass
                //...other more loaders
                //默认有哪些loaders请查看下方默认配置文件
            ]
        },
        plugins:[
            new HtmlWebpackPlugin({
                template: './src/index.html',
                /*
                    默认是'./public/index.html',
                    如果必须要改html的路径则按照这个配置且要安装HtmlWebpackPlugin,
                    不建议修改
                */
                filename: "index.html",
                hash: true
            }),
            //...other more plugins
            //默认有哪些plugins请查看下方默认配置文件
        ]
    },
    dev:{
        devServer:{
            port:8888,//修改端口
        }
    },
    prod:{
        output:{
            publicPath:'http://scdn....',//修改输入文件的publicPath,默认为'/'
        },
    }
}

merge规则请看 https://www.npmjs.com/package/webpack-merge 里merge.smart介绍

默认配置文件

https://git.xchanger.cn/eas/web/ecarx-build/blob/master/src/webpack.common.js https://git.xchanger.cn/eas/web/ecarx-build/blob/master/src/webpack.dev.js https://git.xchanger.cn/eas/web/ecarx-build/blob/master/src/webpack.prod.js

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago