Skip to content

Commit

Permalink
fixe build error html-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
meepobrother committed May 4, 2019
1 parent c3bb97f commit 1cb86b1
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 140 deletions.
13 changes: 0 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@
"devDependencies": {
"@angular/compiler": "^7.2.13",
"@angular/compiler-cli": "^7.2.14",
"@angular/core": "^7.2.13",
"@angular/language-service": "^7.2.13",
"@angular/router": "^7.2.13",
"@babel/core": "^7.4.4",
"@babel/generator": "^7.4.4",
"@babel/parser": "^7.4.4",
"@babel/template": "^7.4.4",
"@babel/traverse": "^7.4.4",
"@babel/types": "^7.4.4",
"@progress-nativechat/nativescript-nativechat": "2.0.3",
"@stencil/core": "^0.18.1",
"@types/autoprefixer": "^9.4.0",
"@types/babel__core": "^7.1.1",
"@types/babel__generator": "^7.0.2",
"@types/babel__template": "^7.0.2",
"@types/babel__traverse": "^7.0.6",
"@types/chai": "^4.1.7",
"@types/csso": "^3.5.1",
"@types/enhanced-resolve": "^3.0.6",
Expand Down
9 changes: 1 addition & 8 deletions packages/nger-compiler/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StaticProvider } from 'nger-di'
import { NgerCompilerImage } from './assets/image'
import { NgerCompilerUglify } from './ts/uglify'
import { NgerCompilerBabel } from './ts/babel'
import { TraverVisitor, Resolver } from 'nger-core'
import { Resolver } from 'nger-core'
import { NgerCompilerTypescript } from './ts/typescript'
import { NgerCompilerRollup } from './ts/rollup'
import { NgerCompilerNgTemplate } from './html/ng'
Expand All @@ -12,7 +12,6 @@ import { NgerCompilerNgMetadata } from './helper/ng_metadata'
import { controllerPropertyTransformerFactory, hasPropertyMetadata } from './transformer_factorys/controller'
import { WATCH_TASK, Task } from './tokens/watch_task'
import { NgerCompilerBootstrap, metadataCache, hasHandlerFileCache, templateCache } from './bootstrap'
import { controllerVisitor } from './visitors/controller'
import { NgModuleBootstrap } from 'nger-core'
import { NgerUtil } from 'nger-util'
export {
Expand Down Expand Up @@ -41,11 +40,6 @@ const provides: StaticProvider[] = [
deps: [NgerUtil],
multi: true
},
{
provide: TraverVisitor,
useValue: controllerVisitor,
multi: true
},
{
provide: NgerCompilerNgMetadata,
useClass: NgerCompilerNgMetadata,
Expand Down Expand Up @@ -82,7 +76,6 @@ const provides: StaticProvider[] = [
useClass: NgerCompilerBabel,
deps: [
NgerCompilerTypescript,
TraverVisitor,
Resolver
]
}
Expand Down
43 changes: 18 additions & 25 deletions packages/nger-compiler/lib/ts/babel.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
import traverse, { Visitor } from '@babel/traverse';
import generator from '@babel/generator';
import { parse } from '@babel/parser';
import { Resolver } from 'nger-core'
import fs from 'fs-extra';
import { Injectable } from 'nger-core';
import { NgerCompilerTypescript } from 'nger-compiler';
import { mergeVisitors } from './util'
import ts from 'typescript';
const {transformSync} = require('@babel/core')
@Injectable()
export class NgerCompilerBabel {
visitor: Visitor;
constructor(
public ts: NgerCompilerTypescript,
public visitors: Visitor[],
public resolver: Resolver
) {
this.visitor = mergeVisitors(this.visitors, this)
}
) {}
getFileContent(path: string, config: ts.TranspileOptions = {}) {
// 如果文件或目录存在
let code = fs.readFileSync(path).toString('utf8')
if (path.endsWith('.ts') || path.endsWith('tsx')) {
code = this.ts.compile(code, config)
}
return code;
}
compile(from: string, config: ts.TranspileOptions = {}) {
try{
// 如果已经处理过了则忽略
// 拿到文件内容
let code = this.getFileContent(from, config);
// 解析
const ast = parse(code, {});
// 替换处理
traverse(ast, this.visitor || {});
code = generator(ast).code;
// 如果文件或目录存在
let code = fs.readFileSync(path).toString('utf8')
if (path.endsWith('.ts') || path.endsWith('tsx')) {
code = this.ts.compile(code, config)
}
return code;
}catch(e){}
}
compile(from: string, config: ts.TranspileOptions = {}) {
// 如果已经处理过了则忽略
// 拿到文件内容
let code = this.getFileContent(from, config);
if(!code){
code = ``;
}
code = transformSync(code, {}).code
return code;
// 解析
}
}
5 changes: 4 additions & 1 deletion packages/nger-compiler/lib/ts/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export class NgerCompilerTypescript {
constructor() { }
compile(content: string, config: ts.TranspileOptions = {}): string {
config = {
compilerOptions: this.options,
compilerOptions: {
...this.options,
target: ts.ScriptTarget.ES5
},
...config,
};
const output = ts.transpileModule(content, config)
Expand Down
32 changes: 0 additions & 32 deletions packages/nger-compiler/lib/ts/util.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/nger-compiler/lib/visitors/controller.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/nger-core/lib/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from './nger-config';
export * from './history';
export * from './file_system';
export * from './resolver';
export * from './traverse';
export * from './router';
export * from './cache';
export * from './h';
Expand Down
6 changes: 3 additions & 3 deletions packages/nger-core/lib/sdk/traverse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Visitor } from '@babel/traverse';
import { InjectionToken } from 'nger-di';
export const TraverVisitor = new InjectionToken<Visitor[]>(`TraverVisitor`)
// import { Visitor } from '@babel/traverse';
// import { InjectionToken } from 'nger-di';
// export const TraverVisitor = new InjectionToken<Visitor[]>(`TraverVisitor`)
5 changes: 1 addition & 4 deletions packages/nger-provider-typescript/lib/babel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as t from '@babel/types';
import template from '@babel/template';
import core from '@babel/core';
import traverse, { NodePath } from '@babel/traverse';
import generator from '@babel/generator';
import { parse } from '@babel/parser';
import tpl from './babel_template';
import { join, dirname, relative, extname } from 'path'
import { join, dirname, extname } from 'path'
const root = process.cwd();
import fs from 'fs-extra';
import { Injectable } from 'nger-core';
Expand Down
17 changes: 2 additions & 15 deletions packages/nger-webpack-admin/lib/app_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { join } from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack, { Configuration } from 'webpack'
const StatsPlugin = require('stats-webpack-plugin');

export function init(injector: Injector) {
const manager = injector.get(NgerWebpackManager)
return () => {
Expand All @@ -28,7 +27,7 @@ export function init(injector: Injector) {
main: [join(root, `.temp/addon/${name}/admin.js`)]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
extensions: ['.js', '.jsx'],
mainFields: ['main:h5', 'main', 'module'],
symlinks: true,
modules: [join(root, 'node_modules'), join(root, 'packages')]
Expand All @@ -53,19 +52,7 @@ export function init(injector: Injector) {
],
output: output,
module: {
rules: [{
test: /\.tsx?$/,
enforce: 'pre',
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
configFile: 'tsconfig.json'
}
}
]
}, ...assetsRules]
rules: [...assetsRules]
},
performance: {
hints: 'warning',
Expand Down
2 changes: 1 addition & 1 deletion packages/nger-webpack-admin/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default [{
useFactory: init,
deps: [Injector],
multi: true
}]
}];
9 changes: 3 additions & 6 deletions packages/nger-webpack-app/lib/app_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { join } from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack, { Configuration } from 'webpack'
const StatsPlugin = require('stats-webpack-plugin');

export function init(injector: Injector) {
const manager = injector.get(NgerWebpackManager)
return () => {
Expand All @@ -17,18 +16,16 @@ export function init(injector: Injector) {
filename: '[name]_[hash].bound.js',
chunkFilename: '[name]_[hash].chunk.js'
}
const optimi = dev ? {} : optimization;
const name = getCurrentDev();
if (!name) {
throw new Error(`当前开发项目不纯在`)
}
const chunks = dev ? ['main'] : ['runtime', 'vendor', 'common', 'main']
manager.options.push({
entry: {
main: [join(root, `.temp/addon/${name}/app.js`)]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
extensions: ['.js', '.jsx'],
mainFields: ['main:h5', 'main', 'module'],
symlinks: true,
modules: [join(root, 'node_modules'), join(root, 'packages')]
Expand All @@ -48,7 +45,7 @@ export function init(injector: Injector) {
cache: false,
template: join(__dirname, 'index.html'),
filename: 'index.html',
chunks: chunks,
chunks: ['runtime', 'vendor', 'common', 'main'],
}),
new webpack.WatchIgnorePlugin([
/\.d\.ts$/
Expand Down Expand Up @@ -76,7 +73,7 @@ export function init(injector: Injector) {
maxEntrypointSize: 1700000,
maxAssetSize: 1700000
},
...optimi
...optimization
} as Configuration)
}
}
8 changes: 3 additions & 5 deletions packages/nger-webpack-pc/lib/app_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ export function init(injector: Injector) {
filename: '[name]_[hash].bound.js',
chunkFilename: '[name]_[hash].chunk.js'
}
const optimi = dev ? {} : optimization;
const name = getCurrentDev();
if (!name) {
throw new Error(`当前开发项目不纯在`)
}
const chunks = dev ? ['main'] : ['runtime', 'vendor', 'common', 'main']
manager.options.push({
entry: {
main: [join(root, `.temp/addon/${name}/pc.js`)]
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
extensions: ['.js', '.jsx'],
mainFields: ['main:h5', 'main', 'module'],
symlinks: true,
modules: [join(root, 'node_modules'), join(root, 'packages')]
Expand All @@ -48,7 +46,7 @@ export function init(injector: Injector) {
cache: false,
template: join(__dirname, 'index.html'),
filename: 'index.html',
chunks: chunks,
chunks: ['runtime', 'vendor', 'common', 'main'],
}),
new webpack.WatchIgnorePlugin([
/\.d\.ts$/
Expand Down Expand Up @@ -76,7 +74,7 @@ export function init(injector: Injector) {
maxEntrypointSize: 1700000,
maxAssetSize: 1700000
},
...optimi
...optimization
} as Configuration)
}
}
12 changes: 0 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@
"nger-dom": [
"packages/nger-dom/lib/index.ts"
],
"@babel/core": [
"node_modules/@types/babel__core"
],
"@babel/generator": [
"node_modules/@types/babel__generator"
],
"@babel/template": [
"node_modules/@types/babel__template"
],
"@babel/traverse": [
"node_modules/@types/babel__traverse"
],
"*": [
"./node_modules/*",
"packages/*"
Expand Down
6 changes: 0 additions & 6 deletions yarn-error.log
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ npm manifest:
"@angular/core": "^7.2.13",
"@angular/language-service": "^7.2.13",
"@angular/router": "^7.2.13",
"@babel/core": "^7.4.4",
"@babel/generator": "^7.4.4",
"@babel/parser": "^7.4.4",
"@babel/template": "^7.4.4",
"@babel/traverse": "^7.4.4",
"@babel/types": "^7.4.4",
"@progress-nativechat/nativescript-nativechat": "2.0.3",
"@stencil/core": "^0.18.1",
"@types/autoprefixer": "^9.4.0",
Expand Down

0 comments on commit 1cb86b1

Please sign in to comment.