Skip to content

Feature/build app #4

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

Merged
merged 5 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions docs/docs/scripsts.md → docs/docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Scripts
sidebar_label: Scripts
---

## Start the project
## Start the development application

Using [webpack](https://webpack.js.org/) with reference to folder `src/dev`.

Expand All @@ -14,7 +14,7 @@ npm start
yarn start
```

## Build the project
## Build the library

Using [babel](https://babeljs.io/) with reference to folder `src/lib`.

Expand All @@ -24,6 +24,16 @@ npm build
yarn build
```

## Build the developmento application

Using [webpack](https://webpack.js.org/) with reference to folder `src/dev`.

```
npm build:app
// OR
yarn build:app
```

## Test the project

Using [jest](https://jestjs.io/) with reference to folder `src/lib`. Is possible edit the test config in `package.json`.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": ["packages/*"],
"useWorkspaces": true,
"npmClient": "yarn",
"version": "0.5.1"
"version": "0.6.0"
}
2 changes: 1 addition & 1 deletion packages/create-react-dependency/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-react-dependency",
"version": "0.5.1",
"version": "0.6.0",
"description": "Creating react libraries",
"main": "index.js",
"author": "André Lins <[email protected]> (https://andrelmlins.github.io/)",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-react-dependency/stages/createPackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const createPackageJson = (root, name) => {
scripts: {
start: 'react-dependency-scripts start',
build: 'react-dependency-scripts build',
'build:app': 'react-dependency-scripts build-app',
test: 'react-dependency-scripts test'
},
devDependencies: {
react: '^16.12.0',
'react-dom': '^16.12.0',
'react-dependency-scripts': '^0.5.1'
'react-dependency-scripts': '^0.6.0'
},
browserslist: {
production: ['>0.2%', 'not dead', 'not op_mini all'],
Expand Down
14 changes: 12 additions & 2 deletions packages/react-dependency-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![npm version](https://badge.fury.io/js/react-dependency-scripts.svg)](https://www.npmjs.com/package/react-dependency-scripts)

## Start the project
## Start the development application

Using [webpack](https://webpack.js.org/) with reference to folder `src/dev`.

Expand All @@ -12,7 +12,7 @@ npm start
yarn start
```

## Build the project
## Build the library

Using [babel](https://babeljs.io/) with reference to folder `src/lib`.

Expand All @@ -22,6 +22,16 @@ npm build
yarn build
```

## Build the developmento application

Using [webpack](https://webpack.js.org/) with reference to folder `src/dev`.

```
npm build:app
// OR
yarn build:app
```

## Test the project

Using [jest](https://jestjs.io/) with reference to folder `src/lib`. Is possible edit the test config in `package.json`.
Expand Down
143 changes: 95 additions & 48 deletions packages/react-dependency-scripts/configs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,102 @@
"use strict";
'use strict';

const HtmlWebpackPlugin = require("html-webpack-plugin");
const resolverPath = require("../utils/resolverPath");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const resolverPath = require('../utils/resolverPath');

const APP_PATH = resolverPath("src/dev");
const APP_PATH = resolverPath('src/dev');
const BUILD_PATH = resolverPath('build');

const config = {
entry: APP_PATH,
mode: "development",
resolve: {
modules: ["node_modules", "src/lib"],
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: [require.resolve("babel-preset-react-app")]
}
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
"file-loader",
{
loader: "image-webpack-loader"
const configWebpack = ({ mode }) => {
const isEnvProduction = mode === 'production';

return {
entry: APP_PATH,
output: {
path: BUILD_PATH,
pathinfo: !isEnvProduction,
filename: isEnvProduction
? 'static/js/[name].[contenthash:8].js'
: 'bundle.js',
chunkFilename: isEnvProduction
? 'static/js/[name].[contenthash:8].chunk.js'
: 'static/js/[name].chunk.js',
globalObject: 'this'
},
mode,
bail: isEnvProduction,
resolve: {
modules: [
'node_modules',
resolverPath('node_modules'),
resolverPath('src')
],
extensions: ['.ts', '.tsx', '.js', '.json']
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: require.resolve('babel-loader'),
exclude: /node_modules/,
options: {
babelrc: false,
configFile: false,
compact: isEnvProduction,
sourceMaps: false,
inputSourceMap: false,
presets: [require.resolve('babel-preset-react-app')]
}
]
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: ['file-loader', { loader: 'image-webpack-loader' }]
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
optimization: { minimize: isEnvProduction },
node: {
module: 'empty',
dgram: 'empty',
dns: 'mock',
fs: 'empty',
http2: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
plugins: [
new HtmlWebpackPlugin(
Object.assign(
{},
{ inject: true, template: `${APP_PATH}/index.html` },
isEnvProduction
? {
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}
: undefined
)
)
]
},

plugins: [
new HtmlWebpackPlugin({
inject: true,
template: `${APP_PATH}/index.html`
})
],

optimization: { minimize: false }
};
};

module.exports = config;
module.exports = configWebpack;
2 changes: 1 addition & 1 deletion packages/react-dependency-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ process.on('unhandledRejection', err => {
const { spawnSync } = require('child_process');

const args = process.argv.slice(2);
const scripts = ['start', 'build', 'test'];
const scripts = ['start', 'build', 'test', 'build-app'];

if (args.length === 0) {
console.log('\x1b[31mEmpty script.');
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dependency-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dependency-scripts",
"version": "0.5.1",
"version": "0.6.0",
"description": "Scripts of react libraries",
"main": "index.js",
"author": "André Lins <[email protected]> (https://andrelmlins.github.io/)",
Expand Down Expand Up @@ -36,6 +36,7 @@
"choose-port": "^0.1.0",
"css-loader": "^3.4.2",
"file-loader": "^5.0.2",
"fs-extra": "^8.1.0",
"html-webpack-plugin": "^3.2.0",
"image-webpack-loader": "^6.0.0",
"jest": "^25.1.0",
Expand Down
27 changes: 27 additions & 0 deletions packages/react-dependency-scripts/scripts/build-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

process.env.NODE_ENV = 'production';
process.env.BABEL_ENV = 'production';

const Webpack = require('webpack');
const fs = require('fs-extra');
const resolverPath = require('../utils/resolverPath');
const configWebpack = require('../configs/webpack.config.js');

const BUILD_PATH = resolverPath('build');

const config = configWebpack({
mode: 'production'
});

fs.emptyDirSync(BUILD_PATH);

const compiler = Webpack(config);

compiler.run((err, stats) => {
if (err) {
return console.log(err);
}

return console.log(stats);
});
6 changes: 5 additions & 1 deletion packages/react-dependency-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ process.on('unhandledRejection', err => {
const Webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const open = require('open');
const config = require('../configs/webpack.config.js');
const configWebpack = require('../configs/webpack.config.js');
const resolverPath = require('../utils/resolverPath');
const choosePort = require('choose-port');

const APP_PATH = resolverPath('src/dev');

const config = configWebpack({
mode: 'development'
});

const compiler = Webpack(config);
const server = new WebpackDevServer(compiler, {
contentBase: APP_PATH,
Expand Down