8000 feat: add Vite optimizations, bug fixes, add sourcemap option for builders by lamnhan · Pull Request #13 · tinijs/tinijs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add Vite optimizations, bug fixes, add sourcemap option for builders #13

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 7 commits into from
Apr 26, 2024
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
15 changes: 1 addition & 14 deletions apps/tinijs.dev/content/framework-posts/103 - dev-build/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,7 @@ Homepage: <https://webpack.js.org/>
### Option 2: Or, manually

1. Install: `npm i -D webpack webpack-cli webpack-dev-server html-bundler-webpack-plugin ts-loader`
2. Add _webpack.config.cjs_, please see [example](https://github.com/tinijs/tinijs/blob/main/packages/webpack-builder/webpack.config.cjs).
2. Add _webpack.config.js_, please see [example](https://github.com/tinijs/tinijs/blob/main/packages/webpack-builder/webpack.config.js).
3. Add scripts:
- **dev**: `webpack serve --history-api-fallback --mode development`
- **build**: `webpack build --mode production`

### Additional setup

Either using Tini CLI or setup manually, you need to do these additional setup.

- Modify _tsconfig.json_
```json
{
"compilerOptions": {
"declaration": false
}
}
```
6 changes: 6 additions & 0 deletions apps/tinijs.dev/tini.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {defineTiniConfig} from '@tinijs/project';

export default defineTiniConfig({
build: {
options: {
configPath: '../../packages/vite-builder/vite.config.js',
},
},

modules: ['@tinijs/content'],

cli: {
Expand Down
5 changes: 4 additions & 1 deletion apps/tinijs.dev/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["**/*"]
"include": [
".app/**/*",
"**/*"
]
}
126 changes: 126 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions packages/cli/cli/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export async function loadBuilder(tiniProject: TiniProject) {
}

export function exposeEnvs(tiniConfig: TiniConfig, targetEnv: string) {
const {srcDir, outDir, compileDir, entryDir, dirs} =
getProjectDirs(tiniConfig);
const projectDirs = getProjectDirs(tiniConfig);
process.env.NODE_ENV = targetEnv;
process.env.TARGET_ENV = targetEnv;
process.env.TINI_SRC_DIR = srcDir;
process.env.TINI_COMPILE_DIR = compileDir;
process.env.TINI_OUT_DIR = outDir;
process.env.TINI_ENTRY_DIR = entryDir;
process.env.TINI_DIRS_PUBLIC = dirs.public;
process.env.TINI_PROJECT_DIRS = JSON.stringify(projectDirs);
process.env.TINI_COMPILE_OPTIONS = JSON.stringify(
(tiniConfig.compile === false || tiniConfig.compile instanceof Function
? undefined
: tiniConfig.compile?.options) || {}
);
process.env.TINI_BUILD_OPTIONS = JSON.stringify(
(tiniConfig.build instanceof Function
? undefined
: tiniConfig.build?.options) || {}
);
}
4 changes: 0 additions & 4 deletions packages/cli/cli/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import cliPackageJSON = require('../../package.json');

export const TINIJS_INSTALL_DIR_PATH = resolve('node_modules', '@tinijs');

export function getTargetEnv() {
return process.env.TARGET_ENV || 'development';
}

export async function loadCLIPackageJSON() {
return cliPackageJSON as PackageJson;
}
Expand Down
32 changes: 20 additions & 12 deletions packages/parcel-builder/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
type CommonBuildOptions,
} from '@tinijs/project';

export type BuildOptions = CommonBuildOptions;
export interface BuildOptions extends CommonBuildOptions {
sourcemap?: boolean;
}

export default function (options: BuildOptions, tiniProject: TiniProject) {
return new ParcelBuilder(options, tiniProject);
Expand All @@ -21,22 +23,22 @@ export class ParcelBuilder implements Builder {
private tiniProject: TiniProject
) {}

get build() {
get dev() {
return {
command: this.commands.buildCommand,
command: this.commands.devCommand,
onServerStart: this.options.onDevServerStart,
};
}

get dev() {
get build() {
return {
command: this.commands.devCommand,
onServerStart: this.options.onDevServerStart,
command: this.commands.buildCommand,
};
}

private get commands() {
const {srcDir, compileDir, outDir, compile} = this.tiniProject.config;
const {configPath, buildCommand, devCommand, devHost, devPort} =
const {configPath, devCommand, devHost, devPort, buildCommand, sourcemap} =
this.options;
const indexFilePath =
compile === false ? `${srcDir}/index.html` : `${compileDir}/index.html`;
Expand All @@ -49,12 +51,8 @@ export class ParcelBuilder implements Builder {
const outDirArgs = ['--dist-dir', outDir];
const hostArgs = !devHost ? [] : ['--host', devHost];
const portArgs = ['--port', `${devPort || '3000'}`];
const sourcemapArgs = sourcemap !== false ? [] : ['--no-source-maps'];
return {
buildCommand:
buildCommand ||
['parcel', 'build', indexFilePath, ...configArgs, ...outDirArgs].filter(
Boolean
),
devCommand:
devCommand ||
[
Expand All @@ -65,6 +63,16 @@ export class ParcelBuilder implements Builder {
...hostArgs,
...portArgs,
].filter(Boolean),
buildCommand:
buildCommand ||
[
'parcel',
'build',
indexFilePath,
...configArgs,
...outDirArgs,
...sourcemapArgs,
].filter(Boolean),
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/project/lib/types/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @ 6CE4 @ import type {TiniProject} from '../classes/project.js';

export interface CommonBuildOptions {
configPath?: string;
buildCommand?: string | string[];
// dev
devCommand?: string | string[];
devPort?: number;
devHost?: string;
onDevServerStart?: () => void;
// build
buildCommand?: string | string[];
}

export interface Builder {
Expand Down
Loading
0