fix(core): update
This commit is contained in:
parent
a265493eba
commit
33e73e9959
12496
package-lock.json
generated
12496
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,8 +21,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@types/parcel-bundler": "1.12.3",
|
"@parcel/core": "^2.3.2"
|
||||||
"parcel-bundler": "1.12.3"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -1,64 +1,91 @@
|
|||||||
import * as plugins from './smartparcel.plugins';
|
import * as plugins from './smartparcel.plugins';
|
||||||
|
|
||||||
export class Parcel {
|
export class Parcel {
|
||||||
private defaultOptions: plugins.parcel.ParcelOptions = {
|
private options: {
|
||||||
outDir: plugins.path.join(process.cwd(), './dist_watch'), // The out directory to put the build files in, defaults to dist
|
from: string | string[],
|
||||||
outFile: 'index.html', // The name of the outputFile
|
outputDir: string,
|
||||||
publicUrl: '/', // The url to serve on, defaults to '/'
|
outputFile: string
|
||||||
watch: true, // Whether to watch the files and rebuild them on change, defaults to process.env.NODE_ENV !== 'production'
|
} = {
|
||||||
cache: true, // Enabled or disables caching, defaults to true
|
from: null,
|
||||||
cacheDir: '.nogit/.parcelcache', // The directory cache gets put in, defaults to .cache
|
outputDir: null,
|
||||||
contentHash: false, // Disable content hash from being included on the filename
|
outputFile: null,
|
||||||
global: 'moduleName', // Expose modules as UMD under this name, disabled by default
|
}
|
||||||
minify: false, // Minify files, enabled if process.env.NODE_ENV === 'production'
|
private defaultOptions: ConstructorParameters<typeof plugins.parcel.Parcel>[ 0 ] = {
|
||||||
scopeHoist: false, // Turn on experimental scope hoisting/tree shaking flag, for smaller production bundles
|
defaultConfig: '@parcel/config-default',
|
||||||
target: 'browser', // Browser/node/electron, defaults to browser
|
cacheDir: './.nogit/.parcelcache',
|
||||||
bundleNodeModules: true, // By default, package.json dependencies are not included when using 'node' or 'electron' with 'target' option above. Set to true to adds them to the bundle, false by default
|
defaultTargetOptions: {
|
||||||
https: null,
|
distDir: plugins.path.join(process.cwd(), './dist_watch'),
|
||||||
logLevel: 3, // 5 = save everything to a file, 4 = like 3, but with timestamps and additionally log http requests to dev server, 3 = log info, warnings & errors, 2 = log warnings & errors, 1 = log errors, 0 = log nothing
|
publicUrl: '/',
|
||||||
hmr: true, // Enable or disable HMR while watching
|
engines: {
|
||||||
hmrPort: 3003, // The port the HMR socket runs on, defaults to a random free port (0 in node.js resolves to a random free port)
|
browsers: [ 'last 1 Chrome version' ]
|
||||||
sourceMaps: true, // Enable or disable sourcemaps, defaults to enabled (minified builds currently always create sourcemaps)
|
}
|
||||||
hmrHostname: '', // A hostname for hot module reload, default to ''
|
},
|
||||||
detailedReport: false, // Prints a detailed report of the bundles, assets, filesizes and times, defaults to false, reports are only printed if watch is disabled
|
entries: './html/index.html',
|
||||||
|
hmrOptions: {
|
||||||
|
port: 3003
|
||||||
|
},
|
||||||
|
serveOptions: {
|
||||||
|
port: 3002
|
||||||
|
}
|
||||||
};
|
};
|
||||||
public options: plugins.parcel.ParcelOptions;
|
|
||||||
public entryFiles: string | string[] = plugins.path.join(process.cwd(), './html/index.html');
|
public entryFiles: string | string[] = plugins.path.join(process.cwd(), './html/index.html');
|
||||||
|
|
||||||
|
|
||||||
|
public async createOptions() {
|
||||||
|
const returnOptions: ConstructorParameters<typeof plugins.parcel.Parcel>[ 0 ] = {
|
||||||
|
...this.defaultOptions,
|
||||||
|
entries: this.options.from,
|
||||||
|
defaultTargetOptions: {
|
||||||
|
...this.defaultOptions.defaultTargetOptions,
|
||||||
|
distDir: this.options.outputDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnOptions;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* builds and serves
|
* builds and serves
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async watchAndServe () {
|
||||||
const bundler = new plugins.parcel(this.entryFiles, this.options);
|
const bundler = new plugins.parcel.Parcel(await this.createOptions());
|
||||||
|
|
||||||
// Run the bundler, this returns the main bundle
|
let subscription = await bundler.watch((err, event) => {
|
||||||
// Use the events if you're using watch mode as this promise will only trigger once and not for every rebuild
|
if (err) {
|
||||||
const bundle = await bundler.serve(3002);
|
// fatal error
|
||||||
|
console.log(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type === 'buildSuccess') {
|
||||||
|
let bundles = event.bundleGraph.getBundles();
|
||||||
|
console.log(`✨ Built ${bundles.length} bundles in ${event.buildTime}ms!`);
|
||||||
|
} else if (event.type === 'buildFailure') {
|
||||||
|
console.log(event.diagnostics);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* just builds
|
* just builds
|
||||||
*/
|
*/
|
||||||
public async build() {
|
public async build () {
|
||||||
const bundler = new plugins.parcel(this.entryFiles, {
|
let bundler = new plugins.parcel.Parcel(await this.createOptions());
|
||||||
...this.options,
|
|
||||||
watch: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Run the bundler, this returns the main bundle
|
try {
|
||||||
// Use the events if you're using watch mode as this promise will only trigger once and not for every rebuild
|
let {bundleGraph, buildTime} = await bundler.run();
|
||||||
const bundle = await bundler.bundle().catch((e) => {
|
let bundles = bundleGraph.getBundles();
|
||||||
console.error(e);
|
console.log(`✨ Built ${bundles.length} bundles in ${buildTime}ms!`);
|
||||||
throw e;
|
} catch (err: any) {
|
||||||
});
|
console.log(err.diagnostics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(fromArg: string | string[], outputDirArg: string, outputFileArg: string) {
|
constructor(fromArg: string | string[], outputDirArg: string, outputFileArg: string) {
|
||||||
this.entryFiles = fromArg;
|
this.entryFiles = fromArg;
|
||||||
this.options = {
|
this.options = {
|
||||||
...this.defaultOptions,
|
from: fromArg,
|
||||||
outDir: outputDirArg,
|
outputDir: outputDirArg,
|
||||||
outFile: outputFileArg,
|
outputFile: outputFileArg
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,6 @@ import * as smartpath from '@pushrocks/smartpath';
|
|||||||
export { smartpath };
|
export { smartpath };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import parcel from 'parcel-bundler';
|
import * as parcel from '@parcel/core';
|
||||||
|
|
||||||
export { parcel };
|
export { parcel };
|
||||||
|
Loading…
Reference in New Issue
Block a user