File tree Expand file tree Collapse file tree 11 files changed +1032
-555
lines changed Expand file tree Collapse file tree 11 files changed +1032
-555
lines changed Original file line number Diff line number Diff line change 1- # IntelliJ project files
21.idea
32* .iml
43out
54gen
65node_modules
6+ * .log
7+ test /dist /
Original file line number Diff line number Diff line change 1- const acorn = require ( 'acorn' ) ;
2- const escodegen = require ( 'escodegen' ) ;
3-
4- module . exports = function ( source ) {
5- this . cacheable && this . cacheable ( ) ;
6- const tree = acorn . parse ( source , { sourceType : 'module' } ) ;
7- traverse ( tree ) ;
8- return escodegen . generate ( tree ) ;
9- } ;
10-
11- function isObject ( item ) {
1+ "use strict" ;
2+ var acorn = require ( "acorn" ) ;
3+ var escodegen = require ( "escodegen" ) ;
4+ var isObject = function ( item ) {
125 return Object . prototype . toString . call ( item ) === '[object Object]' ;
13- }
14-
6+ } ;
7+ var acornOptions = {
8+ sourceType : 'module'
9+ } ;
1510function traverse ( input ) {
1611 if ( Array . isArray ( input ) ) {
17- input . forEach ( item => traverse ( item ) ) ;
18- }
12+ input . forEach ( traverse ) ;
13+ }
1914 else if ( isObject ( input ) ) {
20- for ( let key in input ) {
15+ for ( var key in input ) {
2116 if ( typeof input [ key ] === 'string' ) {
2217 input [ key ] = input [ key ] . replace ( / ( \n \s + ) / g, '' ) ;
2318 }
24- traverse ( input [ key ] ) ;
19+ else {
20+ traverse ( input [ key ] ) ;
21+ }
2522 }
2623 }
2724}
25+ module . exports = function ( source ) {
26+ this . cacheable && this . cacheable ( ) ;
27+ var tree = acorn . parse ( source , acornOptions ) ;
28+ traverse ( tree ) ;
29+ return escodegen . generate ( tree ) ;
30+ } ;
Original file line number Diff line number Diff line change 11{
22 "name" : " template-string-optimize-loader" ,
3- "version" : " 2.2.1 " ,
3+ "version" : " 2.2.2 " ,
44 "description" : " template string optimize loader module for webpack" ,
5- "main" : " index.js" ,
5+ "main" : " lib/ index.js" ,
66 "scripts" : {
7- "test" : " webpack && webpack --config webpack.config.optimize.js" ,
8- "release" : " npm publish"
7+ "lib" : " tsc -p tsconfig.json" ,
8+ "test" : " bash ./test/test.sh" ,
9+ "release" : " npm run lib && npm publish"
910 },
1011 "author" : " chenjiahan" ,
1112 "license" : " ISC" ,
1213 "devDependencies" : {
13- "babel" : " ^6.3.26" ,
14- "babel-loader" : " ^6.2.1" ,
15- "babel-preset-es2015" : " ^6.3.13" ,
16- "webpack" : " ^1.12.10"
14+ "@types/acorn" : " ^4.0.2" ,
15+ "@types/escodegen" : " ^0.0.6" ,
16+ "babel" : " ^6.23.0" ,
17+ "babel-core" : " ^6.24.1" ,
18+ "babel-loader" : " ^6.4.1" ,
19+ "babel-preset-es2015" : " ^6.24.1" ,
20+ "typescript" : " ^2.2.2" ,
21+ "webpack" : " ^2.4.1"
1722 },
1823 "bugs" : {
1924 "url" : " https://github.com/chenjiahan/template-string-optimize-loader/issues"
2025 },
2126 "homepage" : " https://github.com/chenjiahan/template-string-optimize-loader#readme" ,
2227 "dependencies" : {
23- "acorn" : " ^4 .0.9 " ,
28+ "acorn" : " ^5 .0.3 " ,
2429 "escodegen" : " ^1.8.1"
2530 }
2631}
Original file line number Diff line number Diff line change 1+ import acorn = require( 'acorn' ) ;
2+ import escodegen = require( 'escodegen' ) ;
3+
4+ const isObject = ( item : any ) : boolean =>
5+ Object . prototype . toString . call ( item ) === '[object Object]' ;
6+
7+ const acornOptions = {
8+ sourceType : 'module'
9+ } as acorn . Options ;
10+
11+ export = function ( source : string ) : string {
12+ this . cacheable && this . cacheable ( ) ;
13+ const tree = acorn . parse ( source , acornOptions ) ;
14+ traverse ( tree ) ;
15+ return escodegen . generate ( tree ) ;
16+ } ;
17+
18+ function traverse ( input : any ) : void {
19+ if ( Array . isArray ( input ) ) {
20+ input . forEach ( traverse ) ;
21+ } else if ( isObject ( input ) ) {
22+ for ( let key in input ) {
23+ if ( typeof input [ key ] === 'string' ) {
24+ input [ key ] = input [ key ] . replace ( / ( \n \s + ) / g, '' ) ;
25+ } else {
26+ traverse ( input [ key ] ) ;
27+ }
28+ }
29+ }
30+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ npm run lib
3+
4+ mkdir node_modules/template-string-optimize-loader
5+ cp -r ./package.json ./node_modules/template-string-optimize-loader
6+ cp -r ./lib ./node_modules/template-string-optimize-loader
7+
8+ webpack
9+ webpack --config webpack.config.optimize.js
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "target" : " es5" ,
4+ "module" : " commonjs" ,
5+ "moduleResolution" : " node" ,
6+ "outDir" : " lib" ,
7+ "isolatedModules" : false ,
8+ "experimentalDecorators" : true ,
9+ "noImplicitAny" : true ,
10+ "removeComments" : true ,
11+ "suppressImplicitAnyIndexErrors" : true ,
12+ "allowSyntheticDefaultImports" : true ,
13+ "types" : [
14+ " acorn" ,
15+ " escodegen"
16+ ],
17+ "lib" : [
18+ " es2015"
19+ ]
20+ },
21+ "include" : [
22+ " ./src/*.ts"
23+ ],
24+ "compileOnSave" : false
25+ }
Original file line number Diff line number Diff line change 1+ const path = require ( 'path' ) ;
2+
13module . exports = {
2- entry : " ./test/src/test.js" ,
4+ entry : ' ./test/src/test.js' ,
35 output : {
4- path : " test/dist" ,
5- filename : " test.js"
6+ path : path . resolve ( __dirname , './ test/dist' ) ,
7+ filename : ' test.js'
68 } ,
79 module : {
8- loaders : [
10+ rules : [
911 {
1012 test : / \. j s $ / ,
11- loader : "babel?presets[]=es2015"
13+ use : {
14+ loader : 'babel-loader' ,
15+ options : {
16+ presets : [ 'es2015' ]
17+ }
18+ }
1219 }
1320 ]
1421 }
Original file line number Diff line number Diff line change 1+ const path = require ( 'path' ) ;
2+
13module . exports = {
2- entry : " ./test/src/test.js" ,
4+ entry : ' ./test/src/test.js' ,
35 output : {
4- path : " test/dist" ,
5- filename : " test.min .js"
6+ path : path . resolve ( __dirname , './ test/dist' ) ,
7+ filename : ' test.optimize .js'
68 } ,
79 module : {
8- loaders : [
10+ rules : [
911 {
1012 test : / \. j s $ / ,
11- loader : "template-string-optimize!babel?presets[]=es2015"
13+ use : [
14+ 'template-string-optimize-loader' ,
15+ {
16+ loader : 'babel-loader' ,
17+ options : {
18+ presets : [ 'es2015' ]
19+ }
20+ }
21+ ]
1222 }
1323 ]
1424 }
You can’t perform that action at this time.
0 commit comments