Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update webpack 4.0 #26

Merged
merged 14 commits into from
Aug 28, 2018
Merged
69 changes: 44 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.jparrowsec.cn%2Ftinajs%2Fmina-webpack.svg?type=small)](https://app.fossa.io/projects/git%2Bgithub.jparrowsec.cn%2Ftinajs%2Fmina-webpack?ref=badge_small)

## Get Started

We recommend you to get started with [template-mina](https://github.com/tinajs/template-mina):

```bash
Expand All @@ -20,6 +21,7 @@ npm start
And see how to use with [TinaJS](https://tinajs.github.io/tina/#/guide/package-management-and-build-tools)

## Packages included

- [mina-loader](./packages/mina-loader)

[![npm](https://img.shields.io/npm/v/@tinajs/mina-loader.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-loader)
Expand All @@ -39,6 +41,7 @@ And see how to use with [TinaJS](https://tinajs.github.io/tina/#/guide/package-m
[![license](https://img.shields.io/npm/l/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](./LICENSE)

## Manual Installation

```bash
npm i --save-dev \
@tinajs/mina-entry-webpack-plugin \
Expand All @@ -47,52 +50,61 @@ npm i --save-dev \
```

## Simplest Usage

**webpack.config.js**:

```javascript
const webpack = require('webpack')
const MinaEntryPlugin = require('@tinajs/mina-entry-webpack-plugin')
const MinaRuntimePlugin = require('@tinajs/mina-runtime-webpack-plugin')
const resolve = require('path').resolve
const webpack = require("webpack");
const MinaEntryPlugin = require("@tinajs/mina-entry-webpack-plugin");
const MinaRuntimePlugin = require("@tinajs/mina-runtime-webpack-plugin");
const resolve = require("path").resolve;

module.exports = {
context: resolve('src'),
entry: './app.mina',
context: resolve("src"),
entry: "./app.mina",
output: {
path: resolve('dist'),
filename: '[name]',
publicPath: '/',
path: resolve("dist"),
filename: "[name]",
publicPath: "/",
globalObject: "wx",
},
module: {
rules: [
{
test: /\.mina$/,
use: {
loader: 'mina-loader',
loader: "mina-loader",
options: {
loaders: {
script: 'babel-loader',
},
},
},
},
],
script: "babel-loader"
}
}
}
}
]
},
plugins: [
new MinaEntryPlugin({
map: (entry) => ['es6-promise/dist/es6-promise.auto.js', entry],
}),
new MinaRuntimePlugin({
runtime: './common.js',
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common.js',
minChunks: 2,
map: entry => ["es6-promise/dist/es6-promise.auto.js", entry]
}),
new MinaRuntimePlugin(),
],
}
optimization: {
splitChunks: {
name: "common.js",
minChunks: 2,
minSize: 0,
},
runtimeChunk: {
name: "runtime.js",
},
},
mode: "none",
};
```

**app.mina**:

```html
<config>
{
Expand All @@ -113,6 +125,7 @@ App({
```

**page.mina**:

```html
<config>
{
Expand Down Expand Up @@ -147,22 +160,28 @@ Page({
```

## Examples

- [mina-webpack - Full Example](./example)
- [mina-loader - test](./packages/mina-loader/test)
- [TinaJS - HackerNews Reader](https://github.com/tinajs/tina-hackernews)

## Related Projects

### Best to use with

- [TinaJS](https://github.com/tinajs/tina)

### Scaffolds

- [template-mina](https://github.com/tinajs/template-mina)
- [ambar/new-mina](https://github.com/ambar/new-mina)

### Other package compiler (also alternatives)

- [gulp-mina](https://github.com/tinajs/gulp-mina)

### Got inspiration from

- [Cap32/wxapp-webpack-plugin](https://github.com/Cap32/wxapp-webpack-plugin)
- [CantonJS/wxapp-boilerplate](https://github.com/cantonjs/wxapp-boilerplate)
- [zezhipeng/mina-loader](https://github.com/zezhipeng/mina-loader)
Expand Down
Loading